rm(list=ls())

1 Notes

  • Differential Expression Analysis (DEA): proDA for DEA (no imputation, takes into account missing values)

  • Enrichment analysis (GSEA)

1.1 Current set-up

Lipid_Class_col <- c("brown", "brown1", "chocolate1", "orange", "gold",
                     "olivedrab1", "olivedrab", "limegreen","mediumseagreen",
                     "cadetblue1",  "darkcyan", "blue","darkblue",
                     "darkviolet", "deeppink") 

Differential expression analysis (DEA) with all the cell lines.

  • regression with proDA, for all the cell lines
  • formula: Treatment+ Cell.Line + Cell.Line:Treatment

2 prostate

load(file = paste0("processed_data/R02_se_prostate.rda"))

Reference cell line: 22RV1 Reference treatment: Control

se$Treatment <- gsub(" |-","_",se$Treatment)
se$Treatment <- gsub("_+","_",se$Treatment)
rd <- rowData(se)

se$CL_Trt <- paste(se$Cell.Line, se$Treatment,sep = "_")
cd <- colData(se) %>% as.data.frame() %>% rownames_to_column("colname") 

X <- assays(se)$log %>% as.data.frame() %>% 
  rownames_to_column()%>% pivot_longer(-rowname, names_to = "colname") %>%
  left_join(cd, by = "colname")

df_NA <- X %>% group_by(Cell.Line, Treatment, rowname) %>%
  summarize(sumNAs = sum(is.na(value)))
## `summarise()` has grouped output by 'Cell.Line', 'Treatment'. You can override
## using the `.groups` argument.
df_NA$CL_trt <- paste(df_NA$Cell.Line, df_NA$Treatment, sep = "_")
  

table(se$CL_Trt)
## 
##        22RV1_ALA10      22RV1_Control       22RV1_Fer1_3       22RV1_PunA10 
##                  3                  3                  3                  3 
## 22RV1_PunA10_fer13      22RV1_PunA2.5        22RV1_PunA5        LNCaP_ALA10 
##                  3                  3                  3                  3 
##      LNCaP_Control       LNCaP_Fer1_3       LNCaP_PunA10 LNCaP_PunA10_fer13 
##                  3                  3                  3                  3 
##      LNCaP_PunA2.5        LNCaP_PunA5          PC3_ALA10        PC3_Control 
##                  3                  3                  3                  3 
##         PC3_Fer1_3         PC3_PunA10   PC3_PunA10_fer13        PC3_PunA2.5 
##                  3                  3                  3                  3 
##          PC3_PunA5 
##                  3
se$CL_Trt <- make.names(se$CL_Trt)

evalproDA <- FALSE

if (evalproDA){
  # fit <- proDA(assays(se)$log, design = se$CL_Trt)
  # save(fit, file = "results/R03_fitProDA_prostate.rda")
    se_sub <- list()
  for (i in unique(rd$Lipid_Class)){
    se_sub[[i]] <- se[rd$Lipid_Class==i,]
  }
  fit_list <- lapply(se_sub, function(x) 
    proDA(assays(x)$log, design = x$CL_Trt))
  save(fit_list, file = "results/R03_fitProDA_prostate.rda")
}else{
  load(file = "results/R03_fitProDA_prostate.rda")
}

term2gene <- rowData(se) %>% as.data.frame() %>%
    rownames_to_column("lipid") %>% 
    select(c("Lipid_Class","lipid"))

# for heatmaps
Treatment_col = c("Control" = "red", "ALA10" ="green" ,
                    "Fer1_3" = "goldenrod2",
                    "PunA2.5" = "darkturquoise", "PunA5" = "dodgerblue", 
                    "PunA10" = "dodgerblue4", "PunA10_fer13" = "darkorchid3")
fun_sign <- function(res){
  res$sign <- 0
  res$sign[res$diff>0 &res$adj_pval<0.05 ] = 1
  res$sign[res$diff<0 &res$adj_pval<0.05 ] = -1
  res$sign
}

merge_res_prostate <- function(append = FALSE, 
                               pairs = FALSE){
  
  compare <- paste(cdt1,"vs",cdt2)
  pander(compare)
  inter1 <- paste0("(LNCaP_",cdt1," - LNCaP_",cdt2,") - ",
                 "(X22RV1_",cdt1," - X22RV1_",cdt2,")")
  inter2 <- paste0("(PC3_",cdt1," - PC3_",cdt2,") - ",
                 "(X22RV1_",cdt1," - X22RV1_",cdt2,")")

  ### Effects of treatment, per cell line

  # main effect
  name1 <-  paste0("X22RV1_",cdt1," - X22RV1_",cdt2)
  pander(name1)
  # res_td1 <- test_diff(fit, name1, sort_by = NULL)
  res_td1 <- lapply(fit_list, function(x) test_diff(x, name1, sort_by = NULL))
  res_td1 <- do.call(rbind,res_td1)
  res_td1$adj_pval <- p.adjust(res_td1$pval,method = "fdr")
  
  res_td1$adj_pval[res_td1$adj_pval == 0] <- 
    min(res_td1$adj_pval[res_td1$adj_pval > 0])
  res_td1$sign <- fun_sign(res_td1)
  res_td1 %>% dplyr::select(name, pval, adj_pval, diff, t_statistic) %>% 
    arrange(pval) %>% filter(adj_pval<0.05)  %>% pander()
  
  # main effect
  name2 <-  paste0("LNCaP_",cdt1," - LNCaP_",cdt2)
  pander(name2)
  # res_td2 <- test_diff(fit, name2, sort_by = NULL)
  res_td2 <- lapply(fit_list, function(x) test_diff(x, name2, sort_by = NULL))
  res_td2 <- do.call(rbind,res_td2)
  res_td2$adj_pval <- p.adjust(res_td2$pval,method = "fdr")
  
  res_td2$adj_pval[res_td2$adj_pval == 0] <- 
    min(res_td2$adj_pval[res_td2$adj_pval > 0])
  res_td2$sign <- fun_sign(res_td2)
  res_td2 %>% dplyr::select(name, pval, adj_pval, diff, t_statistic) %>%
    arrange(pval)%>% filter(adj_pval<0.05)  %>% pander()
  
  # main effect
  name3 <-  paste0("PC3_",cdt1," - PC3_",cdt2)
  pander(name3)
  # res_td3 <- test_diff(fit, name3, sort_by = NULL)
  res_td3 <- lapply(fit_list, function(x) test_diff(x, name3, sort_by = NULL))
  res_td3 <- do.call(rbind,res_td3)
  res_td3$adj_pval <- p.adjust(res_td3$pval,method = "fdr")
  res_td3$adj_pval[res_td3$adj_pval == 0] <- 
    min(res_td3$adj_pval[res_td3$adj_pval > 0])
  res_td3$sign <- fun_sign(res_td3)
  res_td3 %>% dplyr::select(name, pval, adj_pval, diff, t_statistic) %>% 
    arrange(pval)%>% filter(adj_pval<0.05)  %>% pander()
  
  
  # interaction terms
  name_int1 <- paste0("int_LNCaP_",cdt1,"_",cdt2)
  name_int2 <- paste0("int_PC3_",cdt1,"_",cdt2)
  
  pander(name_int1)
  # res_td_inter1 <- test_diff(fit, inter1, 
  #                      sort_by = NULL)
  res_td_inter1 <- lapply(fit_list, function(x) test_diff(x, inter1, sort_by = NULL))
  res_td_inter1 <- do.call(rbind,res_td_inter1)
  res_td_inter1$adj_pval <- p.adjust(res_td_inter1$pval,method = "fdr")
  
  res_td_inter1$sign <- fun_sign(res_td_inter1)
  res_td_inter1 %>% dplyr::select(name, pval, adj_pval, diff, t_statistic) %>% 
    arrange(pval)%>% filter(adj_pval<0.05)  %>% pander()
  
  pander(name_int2)
  # res_td_inter2 <- test_diff(fit, inter2, 
  #                      sort_by = NULL)
  res_td_inter2 <- lapply(fit_list, function(x) test_diff(x, inter2, sort_by = NULL))
  res_td_inter2 <- do.call(rbind,res_td_inter2)
  res_td_inter2$adj_pval <- p.adjust(res_td_inter2$pval,method = "fdr")
  res_td_inter2$sign <- fun_sign(res_td_inter2)
  res_td_inter2 %>% dplyr::select(name, pval, adj_pval, diff, t_statistic) %>% 
    arrange(pval)%>% filter(adj_pval<0.05)  %>% pander()

  ### all together
  test <- c(rep(name1, nrow(res_td1)), 
            rep(name2, nrow(res_td2)),
            rep(name3, nrow(res_td3)),
            rep(name_int1, nrow(res_td_inter1)),
            rep(name_int2, nrow(res_td_inter2)))
  
  test <- factor(test, levels = c(name1, name2, name3, name_int1, name_int2))
 
  
  #####
  test2 <- c(name1,name2, name3, inter1, inter2)
  
  df_NA_wide <- df_NA %>% ungroup() %>% 
  dplyr::select(!c(Cell.Line, Treatment)) %>% 
  pivot_wider(names_from = CL_trt, values_from = sumNAs) 

  t2 <- gsub("X22RV1","22RV1", test2)

  tex <- strsplit(t2, split = "-")
  tex <- lapply(tex, function(x) gsub(" |\\(|\\)","",x))
  names(tex) <- c(name1, name2, name3, name_int1, name_int2)
  
  matNumNA = matrix(NA, ncol=3, nrow=length(test))
  numNA = c()
  for (i in 1:length(tex)){
    a = do.call(paste0, as.data.frame(df_NA_wide[,tex[[i]]]))
    names(a) = df_NA_wide$rowname
    numNA = c(numNA, a)
  }
  
  matNumNA = data.frame(name = names(numNA), numNA, 
                        test = rep(names(tex),each = nrow(df_NA_wide)))
  
  ####
  
  df_all <- data.frame(name = rep(res_td1$name,5), test, 
                  lipid_Class = rep(rd$Lipid_Class,5), 
                       logFC = c(res_td1$diff,res_td2$diff,res_td3$diff,
                          res_td_inter1$diff, res_td_inter2$diff),
                  t_statistic = c(res_td1$t_statistic,
                                  res_td2$t_statistic, res_td3$t_statistic,
                          res_td_inter1$t_statistic, res_td_inter2$t_statistic),
                  adj_pval = c(res_td1$adj_pval,res_td2$adj_pval, res_td3$adj_pval,
                          res_td_inter1$adj_pval, res_td_inter2$adj_pval),
                  sign = c(res_td1$sign,res_td2$sign, res_td3$sign,
                          res_td_inter1$sign, res_td_inter2$sign))
  
  df_all <- df_all %>% left_join(matNumNA, by = c("name", "test"))
  
  df_all_wide <- df_all %>% pivot_wider(names_from = test, 
                           values_from = c(logFC, adj_pval, numNA,
                                            sign, t_statistic))
  ### volcano plots
  p_VP <- df_all %>% ggplot(aes(x = logFC, y = -log10(adj_pval),
                           label = name)) +
  geom_point(aes(color = lipid_Class)) + 
  facet_wrap(~test)+ 
  theme_bw() + ggtitle(compare) + 
  scale_color_manual(values = Lipid_Class_col) +
  geom_hline(yintercept = -log10(0.05), 
             linetype=2, color="blue")
  
  # only lipids not totally missing in one condition
  a = expand.grid(c(0,3),c(0,3), c(0,3),c(0,3))
  val4 = do.call(paste0, as.data.frame(a))
  val4 = val4[val4!="0000"]
  val2 = c("30", "03", "33")
  
  df_all_sub = df_all[!df_all$numNA %in% c(val2,val4),]
  p_VP2 <- df_all_sub %>% ggplot(aes(x = logFC, y = -log10(adj_pval),
                           label = name)) +
  geom_point(aes(color = lipid_Class)) + 
  facet_wrap(~test)+ 
  theme_bw() + ggtitle(compare) + 
  scale_color_manual(values = Lipid_Class_col) +
  geom_hline(yintercept = -log10(0.05), 
             linetype=2, color="blue")
  
  ### pairs plots
  upperfun <- function(data,mapping){
    ggplot(data = data, mapping = mapping)+
      geom_point()+
      geom_abline(intercept=0,slope=1, color="gray")   +
      scale_x_continuous(limits =range_val) +
      scale_y_continuous(limits = range_val)
  }
  lowerfun <- function(data,mapping){
    ggplot(data = data, mapping = mapping)+
      geom_point()+
      geom_abline(intercept=0,slope=1, color="gray") +
      scale_x_continuous(limits = range_val) +
      scale_y_continuous(limits = range_val)
  }
  
  p_logFC <- p_pvals <- NULL
  if (pairs){
    # foldchanges
    range_val <- range(df_all_wide[,c(3:7)], na.rm = TRUE)
    p_logFC <- ggpairs(df_all_wide[,c(3:7)],
                       upper = list(continuous = wrap(upperfun)),
            lower = list(continuous = wrap(lowerfun)), 
            diag = list(continuous = "blankDiag")) 
    
    # p_logFC
    # ggplotly(p_logFC)
    
    # pvals
    range_val <- range(-log10(df_all_wide[,c(8:12)]), na.rm = TRUE)
    p_pvals <- ggpairs(-log10(df_all_wide[,c(8:12)]),
                       upper = list(continuous = wrap(upperfun)),
            lower = list(continuous = wrap(lowerfun)), 
            diag = list(continuous = "blankDiag")) 
    
    # p_pvals
    # ggplotly(p_pvals) 
  }
  
  
  #### upsetplot
  
  df <- data.frame(res_td1$sign,res_td2$sign,res_td3$sign,
                          res_td_inter1$sign, res_td_inter2$sign)
  colnames(df) <- c(name1, name2, name3, name_int1, name_int2)
  us_pos <- df %>% as.data.frame() %>% dplyr::mutate_all(~ifelse(.x==1,1,0))
  us_neg <- df %>% as.data.frame() %>% dplyr::mutate_all(~ifelse(.x==-1,1,0))
 
  
  list_ret <- list(df_all=df_all, df_all_wide=df_all_wide, 
                   p_logFC = p_logFC, p_pvals = p_pvals, p_VP = p_VP,
                   p_VP2 = p_VP2,
                   us_pos = us_pos,us_neg=us_neg, effects = tex)
  
  
  #### save results
  write.xlsx(df_all_wide, file = "results/R03_prostate.xlsx",
             sheetName = gsub(" ","",compare), append = append)
  
  return(list_ret)
  
}


#### heatmaps
ht_fun <- function(){
  X <- res$df_all_wide %>% select(c(name,starts_with("logFC_")))
  Y <- res$df_all_wide %>% select(starts_with("adj_pval_"))
  if (sum(Y<0.05)>1){
     
  for (i in 2:ncol(X)){
    X[Y[,(i-1)]>=0.05,i] = NA
  }
  
  # FC
  X_fc = X[rowSums(is.na(X))!=(ncol(X)-1),-1]  %>% as.matrix()
  rownames(X_fc) <- X$name[rowSums(is.na(X))!=(ncol(X)-1)]
  col1 = circlize::colorRamp2(seq(-max(X_fc, na.rm=TRUE), 
                        max(X_fc, na.rm=TRUE), length = 3),
                        c("blue","white","red"))
  names_sig <- X[rowSums(is.na(X))!=(ncol(X)-1),1] %>% pull()
  ht1 <- Heatmap(X_fc, cluster_rows = FALSE, cluster_columns = FALSE, 
          column_title = "Fold changes", col=col1, 
          row_names_gp = gpar(fontsize = 8), 
          column_names_gp  = gpar(fontsize = 8))
  
  # raw values
  X_raw <- assays(se)$raw
  cols <- rev(heat.colors(20))
  X_raw <- X_raw[names_sig,] %>% as.matrix()
  cdtrt <- colData(se)[colnames(X_raw),"Treatment"]
  row_ha = HeatmapAnnotation(Treatment = cdtrt, 
                                col = list(Treatment = Treatment_col),
                             which = "column" )
  ht2 <- Heatmap(X_raw, cluster_rows = FALSE, cluster_columns = FALSE, 
          column_title = "raw values", bottom_annotation = row_ha,
          col=cols, row_names_gp = gpar(fontsize = 8), 
          column_names_gp  = gpar(fontsize = 8))
  
  # z scores
  z_scores_fun <- function(data) {(data-mean(data, na.rm=TRUE))/sd(data, na.rm=TRUE)}
  
  X_zscore <- t(apply(X_raw, 1,z_scores_fun))
  
  col1 = circlize::colorRamp2(seq(-max(X_zscore, na.rm=TRUE), 
                        max(X_zscore, na.rm=TRUE), length = 3),
                        c("blue","white","red"))
  
  cdtrt <- colData(se)[colnames(X_raw),"Treatment"]
  row_ha = HeatmapAnnotation(Treatment = cdtrt, 
                                col = list(Treatment = Treatment_col),
                             which = "column" )
  ht3 <- Heatmap(X_zscore, cluster_rows = FALSE, cluster_columns = FALSE, 
          column_title = "z-scores", bottom_annotation = row_ha, col=col1,
          row_names_gp = gpar(fontsize = 8), 
          column_names_gp  = gpar(fontsize = 8))
  
  list(ht1,ht2,ht3)
  }
 
}

2.1 F test for the interaction effect

# load(file = paste0("processed_data/R02_se_",what_data,".rda"))


## -----------------------------------
# F test for the interaction effect

formFull <- ~ se$Treatment + se$Cell.Line + se$Treatment:se$Cell.Line
cat("formula: ", as.character(formFull))
## formula:  ~ se$Treatment + se$Cell.Line + se$Treatment:se$Cell.Line
design <- model.matrix(formFull)
fitlogFull <- proDA(assays(se)$log, design = design,
                          data_is_log_transformed = TRUE,
                           verbose = FALSE)
fitlogFull$convergence$successful
## [1] TRUE
res <- test_diff(fitlogFull, 
                 reduced_model = ~ se$Treatment + se$Cell.Line ,
                       alternative = "two.sided",
                       pval_adjust_method = "BH",
                       sort_by = "adj_pval",
                       verbose = F) %>%
      as_tibble() %>% dplyr::rename("lipid" = "name", 
                             "adj.P.Val" = "adj_pval")
  

res[res$adj.P.Val<0.05,]
## # A tibble: 14 × 9
##    lipid     pval adj.P.Val f_statistic   df1   df2 avg_abundance n_approx n_obs
##    <chr>    <dbl>     <dbl>       <dbl> <dbl> <dbl>         <dbl>    <dbl> <dbl>
##  1 TG 54… 2.40e-9   6.51e-7       10.8     12  42.0         -3.04     59.0    59
##  2 TG 52… 5.08e-9   6.88e-7        9.70    12  46.0         -3.42     63.0    63
##  3 TG 50… 6.44e-7   5.82e-5        7.12    12  43.0         -3.14     60.0    60
##  4 CE 18… 6.03e-6   4.08e-4        6.14    12  39.8         -3.05     56.9    57
##  5 TG 48… 2.03e-5   7.84e-4        5.76    12  36.0         -4.55     53.0    53
##  6 TG 56… 1.95e-5   7.84e-4        6.01    12  33.2         -4.78     50.3    50
##  7 CE 20… 1.73e-5   7.84e-4        5.45    12  42.2         -6.21     59.2    59
##  8 PE 34… 1.00e-4   3.02e-3        4.78    12  38.2         -3.09     55.3    55
##  9 CE 20… 9.93e-5   3.02e-3        4.48    12  46.0         -3.33     63.0    63
## 10 PE 36… 1.65e-4   4.47e-3        4.95    12  30.7         -3.19     47.8    48
## 11 TG 53… 2.93e-4   7.22e-3        4.04    12  45.0         -4.88     62.0    62
## 12 CE 20… 4.71e-4   1.06e-2        3.82    12  46.0         -3.15     63      63
## 13 PI 33… 1.72e-3   3.32e-2        3.50    12  36.2         -3.09     53.2    52
## 14 TG 52… 1.70e-3   3.32e-2        4.07    12  23.9         -3.99     40.9    41

2.2 PunA 10 vs CTL

cdt1 <- "PunA10"
cdt2 <- "Control"

2.2.1 DEA

res <- merge_res_prostate(append = FALSE)

pander("all the lipids")

all the lipids

res$p_VP

ggplotly(res$p_VP)
pander("only lipids not totally missing in ome condition")

only lipids not totally missing in ome condition

res$p_VP2

ggplotly(res$p_VP2)
pander("upregulated")

upregulated

if(sum(colSums(res$us_pos)>0)>1){
  UpSetR::upset(as.data.frame(res$us_pos), 
                keep.order = TRUE, nsets = ncol(res$us_pos)) %>%
    print()
}

pander("downregulated")

downregulated

if(sum(colSums(res$us_neg)>0)>1){
  UpSetR::upset(as.data.frame(res$us_neg), 
                keep.order = TRUE, nsets = ncol(res$us_neg)) %>%
    print()
}

#### heatmaps
ht_fun()
## [[1]]

## 
## [[2]]

## 
## [[3]]

2.2.2 GSEA

pander("GSEA")

GSEA

df = res$df_all_wide
ranks <- df[,grep("t_statistic_",colnames(df), value=TRUE)]
colnames(ranks) <- sub("t_statistic_","",colnames(ranks))
ll = list()
for (i in unique(term2gene$Lipid_Class)){
  ll[[i]] = term2gene$lipid[term2gene$Lipid_Class==i]
}

for (i in 1:ncol(ranks)){
  print(colnames(ranks)[i])
  rank1 <- ranks[,i] %>% pull()
  names(rank1) = df$name
  fgsea::fgsea(ll,rank1) %>% arrange(pval) %>% print()
}
## [1] "X22RV1_PunA10 - X22RV1_Control"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      CL 0.08072917 0.4813360 0.25720647 -0.4653623 -1.4020718    27
##  2:     Cer 0.08347530 0.4813360 0.20207171 -0.6602838 -1.3861417     7
##  3:      TG 0.09694555 0.4813360 0.16318013  0.4413557  1.3493266    71
##  4:      PG 0.17398946 0.4813360 0.13802224 -0.5801099 -1.2683993     8
##  5:      PC 0.17868852 0.4813360 0.13077714  0.5122595  1.2836482    25
##  6:      DG 0.19253438 0.4813360 0.13880511  0.5885236  1.2891316    13
##  7:      PS 0.32549020 0.6974790 0.10244941 -0.4639513 -1.1146864    12
##  8:    PE O 0.38461538 0.7211538 0.09923333 -0.3884007 -1.0645161    18
##  9:  HexCer 0.46446701 0.7741117 0.09656296  0.6254682  1.0430481     4
## 10:      CE 0.58602151 0.8206612 0.06553210  0.3937463  0.9247756    19
## 11:    PC O 0.60181818 0.8206612 0.06494077  0.3858268  0.8934619    17
## 12:      FC 0.83427495 0.9381818 0.05121843  0.5925926  0.7882653     1
## 13:      SM 0.86630037 0.9381818 0.04821497 -0.3137452 -0.7058796     9
## 14:      PE 0.89230769 0.9381818 0.04371258  0.2631135  0.6401948    23
## 15:      PI 0.93818182 0.9381818 0.04424074  0.2519685  0.5834853    17
##      leadingEdge
##           <list>
##  1: CL 68:2,....
##  2: Cer 40:1....
##  3: TG 54:7,....
##  4: PG 34:1,....
##  5: PC 36:6,....
##  6: DG 36:3,....
##  7: PS 36:2,....
##  8: PE O-40:....
##  9: HexCer 3....
## 10: CE 18:3,....
## 11: PC O-32:....
## 12:           FC
## 13: SM 34:1;....
## 14: PE 34:3,....
## 15: PI 33:0,....
## [1] "LNCaP_PunA10 - LNCaP_Control"
##     pathway         pval        padj    log2err         ES        NES  size
##      <char>        <num>       <num>      <num>      <num>      <num> <int>
##  1:      TG 0.0005541142 0.008311713 0.47727082  0.6879875  1.4393377    71
##  2:      PC 0.0184129352 0.138097014 0.35248786  0.7284835  1.4573577    25
##  3:  HexCer 0.0799573007 0.338787732 0.28780513 -0.6853933 -1.4391750     4
##  4:    PE O 0.0903433953 0.338787732 0.28780513 -0.3377010 -1.2839060    18
##  5:      SM 0.3058823529 0.917647059 0.28201335 -0.3658068 -1.0856286     9
##  6:      PS 0.3733601258 0.932203390 0.20350896 -0.3640940 -1.1949993    12
##  7:     Cer 0.4350282486 0.932203390 0.05773085  0.6077567  1.0619380     7
##  8:      CL 0.5236656596 0.950495050 0.04388798  0.4909318  0.9872661    27
##  9:      PE 0.7247706422 0.950495050 0.02913955  0.4334019  0.8595013    23
## 10:      DG 0.7544783983 0.950495050 0.02878615  0.4208639  0.7917813    13
## 11:      CE 0.7625383828 0.950495050 0.02674567  0.4204959  0.8256954    19
## 12:      FC 0.8605108055 0.950495050 0.05174055 -0.5703704 -0.7652324     1
## 13:      PI 0.8689370485 0.950495050 0.01982611  0.3497906  0.6776936    17
## 14:    PC O 0.9318885449 0.950495050 0.01502987  0.2965980  0.5746368    17
## 15:      PG 0.9504950495 0.950495050 0.14040624 -0.2319392 -0.6665703     8
##      leadingEdge
##           <list>
##  1: TG 48:3,....
##  2: PC 34:3,....
##  3: HexCer 4....
##  4: PE O-40:....
##  5:   SM 41:2;O2
##  6: PS 40:2,....
##  7: Cer 42:2....
##  8: CL 70:7,....
##  9: PE 36:3,....
## 10: DG 36:3,....
## 11: CE 18:3,....
## 12:           FC
## 13: PI 38:6,....
## 14: PC O-40:....
## 15: PG 34:1,....
## [1] "PC3_PunA10 - PC3_Control"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      TG 0.01225094 0.1837642 0.38073040  0.5781669  1.4990280    71
##  2:      DG 0.05723370 0.4292528 0.23779383  0.7344071  1.4530561    13
##  3:      PG 0.15454545 0.7727273 0.16957064 -0.5930297 -1.2853637     8
##  4:      SM 0.21709007 0.7866184 0.14205664 -0.5397227 -1.2156788     9
##  5:      PC 0.29758713 0.7866184 0.08553569  0.5187745  1.1594152    25
##  6:    PE O 0.32692308 0.7866184 0.13574094 -0.4283506 -1.1311337    18
##  7:    PC O 0.36708861 0.7866184 0.12625399 -0.4167803 -1.0783680    17
##  8:      PE 0.48373984 0.8238905 0.06130261  0.4534400  0.9982121    23
##  9:      CE 0.49433428 0.8238905 0.06238615  0.4694242  1.0025276    19
## 10:     Cer 0.57692308 0.8653846 0.07511816 -0.4492471 -0.9375195     7
## 11:      CL 0.63745020 0.8692503 0.10473282 -0.2831632 -0.8535397    27
## 12:  HexCer 0.73375262 0.9133214 0.06224904  0.4906367  0.7782818     4
## 13:      PI 0.79154519 0.9133214 0.04190817  0.3551913  0.7398376    17
## 14:      PS 0.89922481 0.9634551 0.06252374 -0.2745033 -0.6511333    12
## 15:      FC 0.97804391 0.9780439 0.04660151  0.5111111  0.6867927     1
##      leadingEdge
##           <list>
##  1: TG 52:5,....
##  2: DG 36:3,....
##  3: PG 34:1,....
##  4: SM 41:2;....
##  5: PC 36:6,....
##  6: PE O-40:....
##  7: PC O-40:....
##  8: PE 36:6,....
##  9: CE 18:3,....
## 10: Cer 42:1....
## 11: CL 68:2,....
## 12: HexCer 4....
## 13: PI 33:0,....
## 14: PS 36:2,....
## 15:           FC
## [1] "int_LNCaP_PunA10_Control"
##     pathway         pval        padj    log2err         ES        NES  size
##      <char>        <num>       <num>      <num>      <num>      <num> <int>
##  1:      CL 0.0001611270 0.001811785 0.51884808  0.6228800  1.9085193    27
##  2:      TG 0.0002415713 0.001811785 0.51884808  0.4932178  1.8098928    71
##  3:     Cer 0.0137354533 0.068677267 0.38073040  0.7366974  1.6310086     7
##  4:      DG 0.0219779633 0.082417362 0.35248786 -0.5348837 -1.6059893    13
##  5:  HexCer 0.1277372263 0.383211679 0.24133998 -0.7116105 -1.3871844     4
##  6:      PC 0.3522167488 0.880541872 0.07217980  0.3690642  1.1128311    25
##  7:      PE 0.4351050680 0.932368003 0.06197627  0.3532471  1.0468890    23
##  8:    PE O 0.6611675127 0.956015524 0.04380020  0.3193000  0.8943665    18
##  9:      PG 0.6851119895 0.956015524 0.04388798  0.3776389  0.8611014     8
## 10:      FC 0.7682926829 0.956015524 0.05859376 -0.6111111 -0.8106769     1
## 11:      CE 0.7716894977 0.956015524 0.10135074 -0.2401589 -0.8266464    19
## 12:      SM 0.9004149378 0.956015524 0.08679498 -0.2366412 -0.6240754     9
## 13:      PS 0.9522580645 0.956015524 0.02723722  0.2371111  0.6031932    12
## 14:      PI 0.9534282018 0.956015524 0.02730747  0.2171634  0.5969215    17
## 15:    PC O 0.9560155239 0.956015524 0.02716698  0.2143254  0.5891209    17
##      leadingEdge
##           <list>
##  1: CL 70:7,....
##  2: TG 52:0,....
##  3: Cer 42:2....
##  4: DG 36:3,....
##  5: HexCer 4....
##  6: PC 30:0,....
##  7: PE 36:6,....
##  8: PE O-38:....
##  9: PG 34:0,....
## 10:           FC
## 11:      CE 18:3
## 12: SM 41:2;....
## 13: PS 36:2,....
## 14: PI 34:2,....
## 15: PC O-40:....
## [1] "int_PC3_PunA10_Control"
##     pathway      pval      padj    log2err         ES        NES  size
##      <char>     <num>     <num>      <num>      <num>      <num> <int>
##  1:      PE 0.1379310 0.7853810 0.14733121  0.5647417  1.2767747    23
##  2:      TG 0.1386963 0.7853810 0.13725078  0.4511284  1.2347137    71
##  3:      CL 0.1570762 0.7853810 0.13649044  0.5326275  1.2509181    27
##  4:      SM 0.2314815 0.8680556 0.13725078 -0.5918379 -1.2000842     9
##  5:     Cer 0.3508772 0.9937500 0.09139243  0.6264035  1.1168910     7
##  6:  HexCer 0.4882075 0.9937500 0.08943668 -0.6183063 -1.0261063     4
##  7:      PS 0.5000000 0.9937500 0.08862611 -0.4489500 -0.9809758    12
##  8:      PI 0.5714286 0.9937500 0.06364241  0.4376002  0.9355529    17
##  9:      FC 0.8394584 0.9937500 0.05216303 -0.5777778 -0.7641542     1
## 10:    PC O 0.9164619 0.9937500 0.05922192 -0.2834646 -0.6727696    17
## 11:      DG 0.9212411 0.9937500 0.05760911 -0.2954497 -0.6566128    13
## 12:    PE O 0.9386189 0.9937500 0.05998925 -0.2679137 -0.6413604    18
## 13:      CE 0.9560976 0.9937500 0.03824168  0.2720070  0.6009250    19
## 14:      PG 0.9930435 0.9937500 0.03959791  0.2361300  0.4281575     8
## 15:      PC 0.9937500 0.9937500 0.03456643  0.2202030  0.5061634    25
##      leadingEdge
##           <list>
##  1: PE 36:6,....
##  2: TG 53:1,....
##  3: CL 72:3,....
##  4: SM 41:1;....
##  5: Cer 40:1....
##  6: HexCer 4....
##  7: PS 38:0,....
##  8: PI 33:0,....
##  9:           FC
## 10: PC O-40:....
## 11: DG 36:3,....
## 12: PE O-32:....
## 13: CE 22:3,....
## 14: PG 36:0,....
## 15: PC 36:4,....

2.3 ALA 10 vs CTL

cdt1 <- "ALA10"
cdt2 <- "Control"

2.3.1 DEA

res <- merge_res_prostate(append = TRUE)

pander("all the lipids")

all the lipids

res$p_VP

ggplotly(res$p_VP)
pander("only lipids not totally missing in ome condition")

only lipids not totally missing in ome condition

res$p_VP2

ggplotly(res$p_VP2)
pander("upregulated")

upregulated

if(sum(colSums(res$us_pos)>0)>1){
  UpSetR::upset(as.data.frame(res$us_pos), 
                keep.order = TRUE, nsets = ncol(res$us_pos)) %>%
    print()
}

pander("downregulated")

downregulated

if(sum(colSums(res$us_neg)>0)>1){
  UpSetR::upset(as.data.frame(res$us_neg), 
                keep.order = TRUE, nsets = ncol(res$us_neg)) %>%
    print()
}

#### heatmaps
ht_fun()
## [[1]]

## 
## [[2]]

## 
## [[3]]

2.3.2 GSEA

pander("GSEA")

GSEA

df = res$df_all_wide
ranks <- df[,grep("t_statistic_",colnames(df), value=TRUE)]
colnames(ranks) <- sub("t_statistic_","",colnames(ranks))
ll = list()
for (i in unique(term2gene$Lipid_Class)){
  ll[[i]] = term2gene$lipid[term2gene$Lipid_Class==i]
}

for (i in 1:ncol(ranks)){
  print(colnames(ranks)[i])
  rank1 <- ranks[,i] %>% pull()
  names(rank1) = df$name
  fgsea::fgsea(ll,rank1) %>% arrange(pval) %>% print()
}
## [1] "X22RV1_ALA10 - X22RV1_Control"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:  HexCer 0.03784055 0.2967258 0.32177592 -0.8172084 -1.4796251     4
##  2:      TG 0.03956344 0.2967258 0.26635066  0.4459347  1.4611222    71
##  3:    PE O 0.09375000 0.4665261 0.21140019 -0.4972175 -1.4128242    18
##  4:      CL 0.18072289 0.4665261 0.16080140 -0.3871451 -1.2297853    27
##  5:      PG 0.18181818 0.4665261 0.13880511 -0.5666510 -1.2571702     8
##  6:      CE 0.21388368 0.4665261 0.12750532  0.4932461  1.2392472    19
##  7:      SM 0.21771218 0.4665261 0.12503337 -0.5303008 -1.2321490     9
##  8:      PC 0.39414802 0.7390275 0.08383611  0.3969666  1.0554243    25
##  9:      PE 0.45901639 0.7650273 0.09255289 -0.3250061 -0.9856714    23
## 10:     Cer 0.55818182 0.7670330 0.06863256 -0.4416569 -0.9375852     7
## 11:      PI 0.60761905 0.7670330 0.06674261  0.3622047  0.8875978    17
## 12:      DG 0.63253012 0.7670330 0.06736239  0.3847688  0.8702553    13
## 13:    PC O 0.66476190 0.7670330 0.06238615  0.3464567  0.8490066    17
## 14:      PS 0.92040816 0.9861516 0.05039643  0.2548263  0.5645559    12
## 15:      FC 0.99038462 0.9903846 0.04432935  0.5074074  0.6834790     1
##      leadingEdge
##           <list>
##  1: HexCer 4....
##  2: TG 54:7,....
##  3: PE O-36:....
##  4: CL 68:2,....
##  5: PG 34:1,....
##  6: CE 18:3,....
##  7: SM 41:1;....
##  8: PC 36:6,....
##  9: PE 36:6,....
## 10: Cer 40:1....
## 11: PI 33:0,....
## 12: DG 36:3,....
## 13: PC O-32:....
## 14: PS 40:2,....
## 15:           FC
## [1] "LNCaP_ALA10 - LNCaP_Control"
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      TG 1.209073e-05 0.0001813609 0.59332548  0.7561822  1.5433865    71
##  2:      PE 3.791711e-02 0.1916853794 0.32177592 -0.5190117 -1.5728078    23
##  3:  HexCer 3.833708e-02 0.1916853794 0.32177592 -0.8726592 -1.6722974     4
##  4:      CL 1.235602e-01 0.4633507853 0.12503337  0.6465554  1.2548213    27
##  5:      PC 1.888772e-01 0.5666316894 0.09754492  0.6278505  1.2069459    25
##  6:      PI 3.250000e-01 0.8125000000 0.28201335 -0.4338350 -1.1121722    17
##  7:      CE 4.628633e-01 0.9382022472 0.05258990  0.5575575  1.0391414    19
##  8:    PE O 6.319218e-01 0.9382022472 0.03871667  0.5095084  0.9398955    18
##  9:      DG 7.303867e-01 0.9382022472 0.03272419  0.4730383  0.8486963    13
## 10:      PS 8.272727e-01 0.9382022472 0.14463053 -0.2949160 -0.6919918    12
## 11:      FC 8.336520e-01 0.9382022472 0.05195125 -0.5777778 -0.7811448     1
## 12:    PC O 8.904555e-01 0.9382022472 0.02136303  0.3648513  0.6695015    17
## 13:     Cer 9.038687e-01 0.9382022472 0.02491974  0.3705749  0.6263223     7
## 14:      PG 9.195402e-01 0.9382022472 0.02286940  0.3517165  0.6059644     8
## 15:      SM 9.382022e-01 0.9382022472 0.02034262  0.3258831  0.5686783     9
##      leadingEdge
##           <list>
##  1: TG 48:3,....
##  2: PE 36:6,....
##  3: HexCer 4....
##  4: CL 70:7,....
##  5: PC 34:3,....
##  6:      PI 33:0
##  7: CE 18:3,....
##  8: PE O-36:....
##  9: DG 36:4,....
## 10: PS 36:1,....
## 11:           FC
## 12: PC O-40:....
## 13: Cer 42:2....
## 14: PG 34:0,....
## 15: SM 36:1;....
## [1] "PC3_ALA10 - PC3_Control"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      TG 0.02757014 0.4135521 0.35248786  0.4761753  1.5281495    71
##  2:      CE 0.14853195 0.7141794 0.14920754  0.5276939  1.3237847    19
##  3:      CL 0.15143603 0.7141794 0.18470647 -0.4081493 -1.2690231    27
##  4:      SM 0.20309478 0.7141794 0.13355495 -0.5513874 -1.2115231     9
##  5:    PE O 0.30046948 0.7141794 0.11934844 -0.4164718 -1.1266014    18
##  6:     Cer 0.39097744 0.7141794 0.08916471 -0.5225412 -1.0682127     7
##  7:      DG 0.52016985 0.7141794 0.08020234 -0.3973645 -0.9774382    13
##  8:      PC 0.52528548 0.7141794 0.06628422  0.3568002  0.9535006    25
##  9:      PS 0.54372624 0.7141794 0.07217980  0.4169884  0.9356761    12
## 10:      PE 0.57430730 0.7141794 0.08407456 -0.3155340 -0.9245744    23
## 11:    PC O 0.58035714 0.7141794 0.07707367 -0.3498439 -0.9343200    17
## 12:  HexCer 0.61250000 0.7141794 0.08020234  0.5393258  0.8867921     4
## 13:      PG 0.61895551 0.7141794 0.06658921 -0.4360203 -0.9160318     8
## 14:      PI 0.73214286 0.7844388 0.06538342 -0.3098424 -0.8274889    17
## 15:      FC 0.98058252 0.9805825 0.04522474 -0.5074074 -0.6871725     1
##      leadingEdge
##           <list>
##  1: TG 52:5,....
##  2: CE 18:3,....
##  3: CL 68:2,....
##  4: SM 41:2;....
##  5: PE O-40:....
##  6: Cer 42:1....
##  7: DG 36:1,....
##  8: PC 36:6,....
##  9: PS 38:2,....
## 10: PE 36:2,....
## 11: PC O-34:....
## 12: HexCer 4....
## 13: PG 34:1,....
## 14: PI 36:1,....
## 15:           FC
## [1] "int_LNCaP_ALA10_Control"
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      CL 2.289616e-05 0.0003434424 0.57561026  0.6612638  2.0293076    27
##  2:      TG 3.537415e-02 0.2444444444 0.28201335  0.3751019  1.4132082    71
##  3:  HexCer 4.888889e-02 0.2444444444 0.24891111  0.7829129  1.4278315     4
##  4:    PE O 9.275362e-02 0.3478260870 0.17520405  0.4910292  1.3477904    18
##  5:      CE 1.242038e-01 0.3726114650 0.22798720 -0.4370971 -1.3131180    19
##  6:      SM 2.765648e-01 0.5607476636 0.09435636  0.5045048  1.1461491     9
##  7:      PC 3.304965e-01 0.5607476636 0.08289621  0.3671294  1.1068373    25
##  8:      DG 3.333333e-01 0.5607476636 0.13010563 -0.4069767 -1.0752159    13
##  9:      PG 3.728571e-01 0.5607476636 0.07687367  0.4883977  1.0862729     8
## 10:      PI 3.738318e-01 0.5607476636 0.12384217 -0.3735868 -1.0702299    17
## 11:      PS 4.531722e-01 0.6179620983 0.10882013 -0.3899614 -1.0049053    12
## 12:     Cer 5.451895e-01 0.6814868805 0.05909548  0.4438176  0.9451419     7
## 13:    PC O 7.312775e-01 0.8437817689 0.04586203  0.3042717  0.8246193    17
## 14:      PE 8.717105e-01 0.8949494949 0.07608372 -0.2328846 -0.7369736    23
## 15:      FC 8.949495e-01 0.8949494949 0.05121843 -0.5518519 -0.7430596     1
##      leadingEdge
##           <list>
##  1: CL 68:2,....
##  2: TG 52:0,....
##  3: HexCer 4....
##  4: PE O-40:....
##  5: CE 18:3,....
##  6: SM 41:1;....
##  7: PC 30:0,....
##  8: DG 36:3,....
##  9: PG 34:0,....
## 10:      PI 33:0
## 11: PS 40:2,....
## 12: Cer 42:2....
## 13: PC O-40:....
## 14:      PE 34:3
## 15:           FC
## [1] "int_PC3_ALA10_Control"
##     pathway      pval      padj    log2err         ES        NES  size
##      <char>     <num>     <num>      <num>      <num>      <num> <int>
##  1:      DG 0.1000000 0.9964974 0.18820415 -0.6118086 -1.3701802    13
##  2:      TG 0.1811723 0.9964974 0.13574094 -0.3638844 -1.1621467    71
##  3:      PI 0.2381786 0.9964974 0.11524000 -0.4979655 -1.1897834    17
##  4:      PE 0.3758701 0.9964974 0.10395847  0.4050442  1.0542475    23
##  5:    PE O 0.4269142 0.9964974 0.09624060  0.4256884  1.0496053    18
##  6:      CE 0.4507042 0.9964974 0.09374654  0.4135356  1.0214419    19
##  7:  HexCer 0.4767184 0.9964974 0.08730983  0.5988993  1.0300150     4
##  8:      CL 0.5594714 0.9964974 0.07829552  0.3401639  0.9355716    27
##  9:      PS 0.7178899 0.9964974 0.06767604  0.3575410  0.8012845    12
## 10:     Cer 0.7766143 0.9964974 0.05101141 -0.4063101 -0.7786956     7
## 11:      PG 0.9004630 0.9964974 0.05724611  0.2965779  0.6038404     8
## 12:      PC 0.9019608 0.9964974 0.04513442 -0.2667336 -0.7028890    25
## 13:      FC 0.9403579 0.9964974 0.04821497  0.5296296  0.7148932     1
## 14:      SM 0.9772727 0.9964974 0.05258990  0.2233870  0.4678191     9
## 15:    PC O 0.9964974 0.9964974 0.03975965 -0.1850394 -0.4421125    17
##      leadingEdge
##           <list>
##  1: DG 36:3,....
##  2: TG 50:4,....
##  3: PI 40:4,....
##  4: PE 36:6,....
##  5: PE O-36:....
##  6: CE 20:5,....
##  7: HexCer 4....
##  8: CL 68:2,....
##  9: PS 38:2,....
## 10: Cer 42:1....
## 11: PG 36:0,....
## 12: PC 34:3,....
## 13:           FC
## 14: SM 41:1;....
## 15: PC O-32:....

2.4 ALA 10 vs PunA 20

cdt1 <- "ALA10"
cdt2 <- "PunA10"

2.4.1 DEA

res <- merge_res_prostate(append = TRUE)

pander("all the lipids")

all the lipids

res$p_VP

ggplotly(res$p_VP)
pander("only lipids not totally missing in ome condition")

only lipids not totally missing in ome condition

res$p_VP2

ggplotly(res$p_VP2)
pander("upregulated")

upregulated

if(sum(colSums(res$us_pos)>0)>1){
  UpSetR::upset(as.data.frame(res$us_pos), 
                keep.order = TRUE, nsets = ncol(res$us_pos)) %>%
    print()
}
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

pander("downregulated")

downregulated

if(sum(colSums(res$us_neg)>0)>1){
  UpSetR::upset(as.data.frame(res$us_neg), 
                keep.order = TRUE, nsets = ncol(res$us_neg)) %>%
    print()
}

#### heatmaps
ht_fun()
## [[1]]

## 
## [[2]]

## 
## [[3]]

2.4.2 GSEA

pander("GSEA")

GSEA

df = res$df_all_wide
ranks <- df[,grep("t_statistic_",colnames(df), value=TRUE)]
colnames(ranks) <- sub("t_statistic_","",colnames(ranks))
ll = list()
for (i in unique(term2gene$Lipid_Class)){
  ll[[i]] = term2gene$lipid[term2gene$Lipid_Class==i]
}

for (i in 1:ncol(ranks)){
  print(colnames(ranks)[i])
  rank1 <- ranks[,i] %>% pull()
  names(rank1) = df$name
  fgsea::fgsea(ll,rank1) %>% arrange(pval) %>% print()
}
## [1] "X22RV1_ALA10 - X22RV1_PunA10"
##     pathway        pval      padj    log2err         ES        NES  size
##      <char>       <num>     <num>      <num>      <num>      <num> <int>
##  1:      CE 0.007092648 0.1063897 0.40701792  0.7186537  1.6984545    19
##  2:      TG 0.083146067 0.4220532 0.23439265  0.4220445  1.2941030    71
##  3:  HexCer 0.101886792 0.4220532 0.19189224 -0.8338074 -1.3542613     4
##  4:      SM 0.127490040 0.4220532 0.17520405 -0.7018814 -1.3646282     9
##  5:    PE O 0.140684411 0.4220532 0.16197895 -0.5807129 -1.3273466    18
##  6:      PC 0.176583493 0.4414587 0.14375899 -0.5175922 -1.2605159    25
##  7:      PE 0.210116732 0.4502501 0.13145761 -0.5153144 -1.2338852    23
##  8:     Cer 0.298210736 0.5591451 0.10882013  0.6184805  1.1773579     7
##  9:      DG 0.365656566 0.6094276 0.09721508 -0.5303192 -1.1105642    13
## 10:      PI 0.439834025 0.6597510 0.08809450  0.4489090  1.0306944    17
## 11:      FC 0.629558541 0.7987452 0.06538342 -0.6888889 -0.9153803     1
## 12:      CL 0.638996139 0.7987452 0.06494077 -0.3600133 -0.8891173    27
## 13:      PS 0.692622951 0.7991803 0.06392719  0.3887297  0.8408211    12
## 14:      PG 0.844488189 0.9048088 0.05269731  0.3560851  0.7000639     8
## 15:    PC O 1.000000000 1.0000000 0.04735342  0.2007874  0.4610076    17
##      leadingEdge
##           <list>
##  1: CE 20:3,....
##  2: TG 55:5,....
##  3: HexCer 4....
##  4: SM 41:1;....
##  5: PE O-32:....
##  6: PC 38:5,....
##  7: PE 36:6,....
##  8: Cer 40:1....
##  9: DG 34:4,....
## 10: PI 36:3,....
## 11:           FC
## 12: CL 68:2,....
## 13: PS 36:2,....
## 14: PG 36:2,....
## 15: PC O-32:....
## [1] "LNCaP_ALA10 - LNCaP_PunA10"
##     pathway        pval       padj    log2err         ES        NES  size
##      <char>       <num>      <num>      <num>      <num>      <num> <int>
##  1:      PE 0.004310851 0.06466276 0.40701792 -0.7477054 -1.6894088    23
##  2:      TG 0.067484663 0.42468856 0.17232434 -0.5351714 -1.3567163    71
##  3:      CL 0.108627943 0.42468856 0.28780513  0.3696614  1.3387663    27
##  4:      PC 0.113250283 0.42468856 0.13725078 -0.6120318 -1.3952369    25
##  5:      PG 0.154440154 0.43674699 0.22496609  0.5392134  1.3606855     8
##  6:    PC O 0.174698795 0.43674699 0.26635066  0.4151186  1.2983419    17
##  7:    PE O 0.204968944 0.43921917 0.24891111  0.3898423  1.2543150    18
##  8:      SM 0.259259259 0.48611111 0.17669427  0.4540742  1.1774040     9
##  9:     Cer 0.332413793 0.55402299 0.08108021 -0.6130055 -1.1373036     7
## 10:      PI 0.376794258 0.56519139 0.06736239 -0.5071274 -1.0936596    17
## 11:      DG 0.518796992 0.70745044 0.05434344 -0.4630633 -0.9526787    13
## 12:      CE 0.684023669 0.82417582 0.03903553 -0.3784472 -0.8285760    19
## 13:  HexCer 0.714285714 0.82417582 0.04754342 -0.4890593 -0.8180769     4
## 14:      PS 0.771028037 0.82610147 0.10282184  0.2741619  0.7668683    12
## 15:      FC 0.989384289 0.98938429 0.04889708 -0.5074074 -0.6683274     1
##      leadingEdge
##           <list>
##  1: PE 36:6,....
##  2: TG 48:3,....
##  3: CL 72:11....
##  4: PC 36:6,....
##  5: PG 36:0,....
##  6: PC O-34:....
##  7: PE O-40:....
##  8:   SM 41:2;O2
##  9: Cer 34:1....
## 10: PI 33:0,....
## 11: DG 34:2,....
## 12: CE 22:3,....
## 13: HexCer 4....
## 14: PS 40:2,....
## 15:           FC
## [1] "PC3_ALA10 - PC3_PunA10"
##     pathway        pval       padj    log2err         ES        NES  size
##      <char>       <num>      <num>      <num>      <num>      <num> <int>
##  1:      DG 0.003940506 0.05910759 0.40701792 -0.7365746 -1.6473429    13
##  2:      CE 0.016503448 0.12377586 0.35248786  0.6291235  1.6600346    19
##  3:      PS 0.039848675 0.19924337 0.32177592  0.6689619  1.5741585    12
##  4:      PE 0.077265973 0.28974740 0.19578900 -0.5374057 -1.3551859    23
##  5:      TG 0.150000000 0.45000000 0.13145761 -0.3845716 -1.2166011    71
##  6:      CL 0.218658892 0.54664723 0.10882013 -0.4568324 -1.1949701    27
##  7:     Cer 0.373887240 0.70675105 0.07871138 -0.5743381 -1.0972940     7
##  8:      PI 0.398791541 0.70675105 0.07627972 -0.4554144 -1.0681786    17
##  9:  HexCer 0.424050633 0.70675105 0.11623415  0.5842697  1.0314624     4
## 10:      SM 0.483918129 0.71316614 0.06494077 -0.4961832 -1.0066006     9
## 11:      PC 0.542097489 0.71316614 0.05998925 -0.3710754 -0.9482267    25
## 12:      PG 0.570532915 0.71316614 0.09688777  0.4258555  0.9117146     8
## 13:    PC O 0.626470588 0.72285068 0.08783126  0.3425197  0.8914634    17
## 14:    PE O 0.794336811 0.85107515 0.04275914 -0.3291112 -0.7881331    18
## 15:      FC 0.990530303 0.99053030 0.04362512 -0.5074074 -0.6763182     1
##      leadingEdge
##           <list>
##  1: DG 34:1,....
##  2: CE 20:5,....
##  3: PS 40:5,....
##  4: PE 36:6,....
##  5: TG 53:1,....
##  6: CL 72:3,....
##  7: Cer 42:2....
##  8: PI 36:3,....
##  9: HexCer 4....
## 10: SM 36:1;....
## 11: PC 40:4,....
## 12: PG 32:0,....
## 13: PC O-36:....
## 14: PE O-36:....
## 15:           FC
## [1] "int_LNCaP_ALA10_PunA10"
##     pathway         pval        padj    log2err         ES        NES  size
##      <char>        <num>       <num>      <num>      <num>      <num> <int>
##  1:      PE 0.0004624682 0.006370587 0.49849311 -0.7559460 -1.7530125    23
##  2:      CE 0.0008831596 0.006370587 0.47727082 -0.7647952 -1.7193144    19
##  3:      SM 0.0012741175 0.006370587 0.45505987  0.8474288  1.9397213     9
##  4:    PE O 0.0022085038 0.008281889 0.43170770  0.6890855  1.9199218    18
##  5:      TG 0.0154904370 0.046471311 0.38073040 -0.5285027 -1.4350582    71
##  6:      CL 0.0709784856 0.177446214 0.28780513  0.4511914  1.3731665    27
##  7:     Cer 0.1354642314 0.290280496 0.14641624 -0.7116979 -1.3069847     7
##  8:  HexCer 0.1897810219 0.333775420 0.15740290  0.7541809  1.3374509     4
##  9:      PI 0.2002652520 0.333775420 0.10839426 -0.5598265 -1.2421211    17
## 10:    PC O 0.4112903226 0.616935484 0.13574094  0.3685978  1.0113233    17
## 11:      PC 0.6086419753 0.829966330 0.04632278 -0.3879602 -0.9145102    25
## 12:      FC 0.8603773585 0.928359474 0.04989074  0.5777778  0.7593930     1
## 13:      DG 0.8645833333 0.928359474 0.07934350  0.2731854  0.6981434    13
## 14:      PG 0.8664688427 0.928359474 0.07113274  0.3079848  0.6694993     8
## 15:      PS 0.9675324675 0.967532468 0.07011322  0.2383135  0.6027458    12
##      leadingEdge
##           <list>
##  1: PE 36:6,....
##  2: CE 20:3,....
##  3: SM 41:1;....
##  4: PE O-40:....
##  5: TG 60:5,....
##  6: CL 72:11....
##  7: Cer 40:1....
##  8: HexCer 4....
##  9: PI 33:0,....
## 10: PC O-34:....
## 11: PC 36:6,....
## 12:           FC
## 13: DG 34:4,....
## 14: PG 36:0,....
## 15: PS 32:1,....
## [1] "int_PC3_ALA10_PunA10"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      TG 0.06258322 0.3504673 0.20658792 -0.4061365 -1.3475603    71
##  2:      PI 0.06666667 0.3504673 0.21392786 -0.5774767 -1.4574850    17
##  3:      DG 0.07009346 0.3504673 0.21140019 -0.6050041 -1.4255070    13
##  4:     Cer 0.14262821 0.4111842 0.14641624 -0.6437907 -1.2978549     7
##  5:    PE O 0.19252874 0.4111842 0.17093234  0.4283403  1.2404534    18
##  6:  HexCer 0.20053476 0.4111842 0.16080140  0.7090467  1.3107286     4
##  7:      PS 0.21204188 0.4111842 0.15419097  0.4683775  1.2340773    12
##  8:      CE 0.21929825 0.4111842 0.16080140  0.4097502  1.1993301    19
##  9:      CL 0.26883309 0.4480551 0.09688777 -0.4155181 -1.1507345    27
## 10:      PE 0.34077381 0.5111607 0.08383611 -0.4064870 -1.0939416    23
## 11:      SM 0.41018767 0.5593468 0.10755438  0.4349332  1.0276703     9
## 12:      PG 0.83739837 0.9548715 0.06831109  0.3117871  0.6973891     8
## 13:      PC 0.87654321 0.9548715 0.07253519  0.2360181  0.7329615    25
## 14:      FC 0.89121339 0.9548715 0.05302125  0.5518519  0.7514273     1
## 15:    PC O 0.98538012 0.9853801 0.06407038  0.1811024  0.5142584    17
##      leadingEdge
##           <list>
##  1: TG 53:1,....
##  2: PI 36:3,....
##  3: DG 38:4,....
##  4: Cer 42:2....
##  5: PE O-36:....
##  6: HexCer 4....
##  7: PS 40:5,....
##  8: CE 20:5,....
##  9: CL 72:3,....
## 10: PE 36:4,....
## 11: SM 41:1;....
## 12: PG 34:0,....
## 13: PC 38:5,....
## 14:           FC
## 15: PC O-36:....

2.5 PunA 2.5 vs PunA 5

cdt1 <- "PunA5"
cdt2 <- "PunA2.5"

2.5.1 DEA

res <- merge_res_prostate(append = TRUE)

pander("all the lipids")

all the lipids

res$p_VP

ggplotly(res$p_VP)
pander("only lipids not totally missing in ome condition")

only lipids not totally missing in ome condition

res$p_VP2

ggplotly(res$p_VP2)
pander("upregulated")

upregulated

if(sum(colSums(res$us_pos)>0)>1){
  UpSetR::upset(as.data.frame(res$us_pos), 
                keep.order = TRUE, nsets = ncol(res$us_pos)) %>%
    print()
}

pander("downregulated")

downregulated

if(sum(colSums(res$us_neg)>0)>1){
  UpSetR::upset(as.data.frame(res$us_neg), 
                keep.order = TRUE, nsets = ncol(res$us_neg)) %>%
    print()
}

#### heatmaps
ht_fun()
## [[1]]

## 
## [[2]]

## 
## [[3]]

2.5.2 GSEA

pander("GSEA")

GSEA

df = res$df_all_wide
ranks <- df[,grep("t_statistic_",colnames(df), value=TRUE)]
colnames(ranks) <- sub("t_statistic_","",colnames(ranks))
ll = list()
for (i in unique(term2gene$Lipid_Class)){
  ll[[i]] = term2gene$lipid[term2gene$Lipid_Class==i]
}

for (i in 1:ncol(ranks)){
  print(colnames(ranks)[i])
  rank1 <- ranks[,i] %>% pull()
  names(rank1) = df$name
  fgsea::fgsea(ll,rank1) %>% arrange(pval) %>% print()
}
## [1] "X22RV1_PunA5 - X22RV1_PunA2.5"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      TG 0.01768804 0.2653206 0.35248786  0.4678978  1.4831391    71
##  2:      DG 0.06161972 0.3439803 0.24133998  0.6524919  1.4985745    13
##  3:      CE 0.06879607 0.3439803 0.27128855 -0.5053864 -1.4857340    19
##  4:      PC 0.10361068 0.3885400 0.17232434  0.5175377  1.3947970    25
##  5:    PC O 0.15529412 0.4658824 0.17232434 -0.4594088 -1.3111253    17
##  6:  HexCer 0.21561338 0.5101394 0.12625399 -0.6733624 -1.2125126     4
##  7:      CL 0.26197183 0.5101394 0.14290115 -0.3665417 -1.1574089    27
##  8:      PS 0.27356322 0.5101394 0.12443417 -0.4678466 -1.1805204    12
##  9:      SM 0.30608365 0.5101394 0.10434395  0.5546460  1.1477999     9
## 10:      PI 0.53647059 0.7666016 0.08407456 -0.3253511 -0.9285325    17
## 11:    PE O 0.57457213 0.7666016 0.08243441 -0.3162005 -0.9122019    18
## 12:     Cer 0.61328125 0.7666016 0.06751890  0.4393939  0.8773221     7
## 13:      FC 0.76447106 0.8313574 0.05797548  0.6037037  0.8275456     1
## 14:      PG 0.77593361 0.8313574 0.05909548 -0.3300315 -0.7454575     8
## 15:      PE 0.93667546 0.9366755 0.06157068 -0.2190288 -0.6637744    23
##      leadingEdge
##           <list>
##  1: TG 50:6,....
##  2: DG 36:3,....
##  3: CE 20:5,....
##  4: PC 36:6,....
##  5: PC O-30:....
##  6: HexCer 4....
##  7: CL 68:2,....
##  8: PS 34:1,....
##  9: SM 40:2;....
## 10: PI 38:6,....
## 11: PE O-36:....
## 12: Cer 34:0....
## 13:           FC
## 14: PG 36:2,....
## 15: PE 36:5,....
## [1] "LNCaP_PunA5 - LNCaP_PunA2.5"
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      CL 2.930309e-05 0.0004395463 0.57561026 -0.6295429 -2.0045349    27
##  2:      PS 1.043993e-03 0.0078299491 0.45505987  0.5984556  1.9994542    12
##  3:     Cer 6.066198e-03 0.0303309898 0.40701792 -0.7300125 -1.6831825     7
##  4:  HexCer 4.251676e-02 0.1594378662 0.32177592  0.7041199  1.5123511     4
##  5:      CE 8.361204e-02 0.2158469945 0.16080140 -0.4541699 -1.3410882    19
##  6:      PC 8.633880e-02 0.2158469945 0.15631240 -0.4271694 -1.3438156    25
##  7:      DG 1.701292e-01 0.3645625752 0.24924655  0.3682171  1.2662453    13
##  8:      TG 3.174442e-01 0.5952079108 0.06767604 -0.2982361 -1.1070412    71
##  9:    PC O 3.600451e-01 0.6000752445 0.06674261 -0.3767471 -1.0841386    17
## 10:      SM 4.207390e-01 0.6177547285 0.06184060 -0.4251465 -1.0490710     9
## 11:    PE O 4.530201e-01 0.6177547285 0.05536428 -0.3526708 -1.0292128    18
## 12:      PE 5.577558e-01 0.6971947195 0.04504428 -0.3089253 -0.9532509    23
## 13:      FC 6.687500e-01 0.7042889391 0.06643641  0.6629630  0.8916308     1
## 14:      PG 7.037944e-01 0.7042889391 0.03927586 -0.3598959 -0.8576105     8
## 15:      PI 7.042889e-01 0.7042889391 0.03546650 -0.2995805 -0.8620818    17
##      leadingEdge
##           <list>
##  1: CL 74:8,....
##  2: PS 40:2,....
##  3: Cer 42:1....
##  4: HexCer 4....
##  5: CE 22:6,....
##  6: PC 30:0,....
##  7: DG 36:4,....
##  8: TG 50:1,....
##  9: PC O-38:....
## 10: SM 41:2;....
## 11: PE O-36:....
## 12: PE 36:1,....
## 13:           FC
## 14: PG 36:1,....
## 15: PI 33:0,....
## [1] "PC3_PunA5 - PC3_PunA2.5"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      TG 0.02793873 0.4190809 0.35248786  0.5149708  1.4889561    71
##  2:      CL 0.10075567 0.6345178 0.22496609 -0.4951556 -1.3654236    27
##  3:      PC 0.12690355 0.6345178 0.16080140  0.5516406  1.3384255    25
##  4:    PE O 0.30493274 0.9172662 0.11524000 -0.4637762 -1.1413854    18
##  5:     Cer 0.51158645 0.9172662 0.07200331 -0.4923669 -0.9794328     7
##  6:      PG 0.56261682 0.9172662 0.06961334 -0.4634563 -0.9415633     8
##  7:      SM 0.60266160 0.9172662 0.06705126 -0.4300896 -0.8997723     9
##  8:      CE 0.64428312 0.9172662 0.06157068  0.3809290  0.8580853    19
##  9:      PS 0.66935484 0.9172662 0.06479434 -0.3838019 -0.8485074    12
## 10:  HexCer 0.68840580 0.9172662 0.07235709  0.4794007  0.7980309     4
## 11:    PC O 0.73766816 0.9172662 0.06523531 -0.3365565 -0.8116335    17
## 12:      DG 0.78362573 0.9172662 0.05571042  0.3452230  0.7365418    13
## 13:      PI 0.79496403 0.9172662 0.05132233  0.3232008  0.7222915    17
## 14:      PE 0.90192644 0.9663498 0.04432935  0.2768472  0.6547998    23
## 15:      FC 0.97308489 0.9730849 0.04850598  0.5148148  0.6934390     1
##      leadingEdge
##           <list>
##  1: TG 48:3,....
##  2: CL 68:2,....
##  3: PC 36:6,....
##  4: PE O-40:....
##  5: Cer 42:1....
##  6: PG 36:2,....
##  7: SM 34:1;....
##  8: CE 18:3,....
##  9: PS 36:2,....
## 10: HexCer 4....
## 11: PC O-38:....
## 12: DG 36:4,....
## 13: PI 33:0,....
## 14: PE 36:6,....
## 15:           FC
## [1] "int_LNCaP_PunA5_PunA2.5"
##     pathway         pval        padj    log2err         ES        NES  size
##      <char>        <num>       <num>      <num>      <num>      <num> <int>
##  1:      PS 0.0001237415 0.001856122 0.51884808  0.6917026  2.4787294    12
##  2:     Cer 0.0272146117 0.139772243 0.35248786 -0.7064197 -1.5390086     7
##  3:      CL 0.0364415863 0.139772243 0.24504179 -0.4929394 -1.4859594    27
##  4:      PE 0.0372725980 0.139772243 0.32177592  0.3306452  1.5242775    23
##  5:      PC 0.0745140389 0.223542117 0.16823817 -0.4707110 -1.3995016    25
##  6:    PC O 0.1140754881 0.285188720 0.28780513  0.3379820  1.4151680    17
##  7:  HexCer 0.1439114391 0.294858871 0.22798720  0.5948784  1.2994432     4
##  8:      TG 0.1572580645 0.294858871 0.10632326 -0.3566550 -1.2152523    71
##  9:      PG 0.2736196319 0.456032720 0.08528847 -0.5173569 -1.1759909     8
## 10:      PI 0.3662131519 0.543850267 0.06613262 -0.4003396 -1.0899624    17
## 11:      DG 0.3988235294 0.543850267 0.06378454 -0.4168567 -1.0664725    13
## 12:      SM 0.4623786408 0.577973301 0.05822162 -0.4290770 -1.0061553     9
## 13:      CE 0.6461366181 0.745542252 0.03911552 -0.3147880 -0.8835361    19
## 14:    PE O 0.7018140590 0.751943635 0.03584493 -0.3048277 -0.8394583    18
## 15:      FC 0.7819253438 0.781925344 0.05617666  0.6111111  0.8168476     1
##      leadingEdge
##           <list>
##  1: PS 34:1,....
##  2: Cer 42:1....
##  3: CL 74:8,....
##  4: PE 36:5,....
##  5: PC 38:5,....
##  6: PC O-32:....
##  7: HexCer 4....
##  8: TG 50:6,....
##  9: PG 34:0,....
## 10:      PI 33:0
## 11: DG 36:3,....
## 12: SM 41:2;....
## 13: CE 18:3,....
## 14: PE O-32:....
## 15:           FC
## [1] "int_PC3_PunA5_PunA2.5"
##     pathway      pval      padj    log2err         ES        NES  size
##      <char>     <num>     <num>      <num>      <num>      <num> <int>
##  1:      CE 0.1425703 0.8752515 0.16565670  0.5903765  1.3176253    19
##  2:      DG 0.2047930 0.8752515 0.14205664 -0.6031157 -1.2586862    13
##  3:    PC O 0.2295720 0.8752515 0.12503337  0.5525808  1.2121971    17
##  4:      CL 0.2334004 0.8752515 0.12625399 -0.4778384 -1.1545422    27
##  5:      SM 0.3606557 0.9055300 0.09889030 -0.5555177 -1.1000063     9
##  6:      TG 0.3759690 0.9055300 0.09314546  0.3594288  1.0372141    71
##  7:      PI 0.5573770 0.9055300 0.07473852 -0.4299371 -0.9430561    17
##  8:    PE O 0.5809717 0.9055300 0.07200331 -0.4102419 -0.9135181    18
##  9:      PS 0.6355140 0.9055300 0.06364241  0.4182889  0.8671110    12
## 10:     Cer 0.6430108 0.9055300 0.06994587 -0.4721275 -0.8760734     7
## 11:      PC 0.7349398 0.9055300 0.06011861 -0.3478664 -0.8302265    25
## 12:      PG 0.7872340 0.9055300 0.05960370 -0.3779637 -0.7248866     8
## 13:  HexCer 0.8185328 0.9055300 0.05323865  0.4268886  0.6892015     4
## 14:      FC 0.8451613 0.9055300 0.05676724 -0.5814815 -0.7787898     1
## 15:      PE 0.9979839 0.9979839 0.04613792 -0.2099017 -0.4936754    23
##      leadingEdge
##           <list>
##  1: CE 22:4,....
##  2: DG 40:6,....
##  3: PC O-36:....
##  4: CL 70:3,....
##  5: SM 40:2;....
##  6: TG 55:2,....
##  7: PI 40:5,....
##  8: PE O-40:....
##  9: PS 34:1,....
## 10: Cer 42:1....
## 11: PC 40:8,....
## 12:      PG 40:7
## 13: HexCer 4....
## 14:           FC
## 15: PE 34:3,....

2.6 PunA 5 vs PunA 10

cdt1 <- "PunA10"
cdt2 <- "PunA5"

2.6.1 DEA

res <- merge_res_prostate(append = TRUE)

pander("all the lipids")

all the lipids

res$p_VP

ggplotly(res$p_VP)
pander("only lipids not totally missing in ome condition")

only lipids not totally missing in ome condition

res$p_VP2

ggplotly(res$p_VP2)
pander("upregulated")

upregulated

if(sum(colSums(res$us_pos)>0)>1){
  UpSetR::upset(as.data.frame(res$us_pos), 
                keep.order = TRUE, nsets = ncol(res$us_pos)) %>%
    print()
}

pander("downregulated")

downregulated

if(sum(colSums(res$us_neg)>0)>1){
  UpSetR::upset(as.data.frame(res$us_neg), 
                keep.order = TRUE, nsets = ncol(res$us_neg)) %>%
    print()
}

#### heatmaps
ht_fun()
## [[1]]

## 
## [[2]]

## 
## [[3]]

2.6.2 GSEA

pander("GSEA")

GSEA

df = res$df_all_wide
ranks <- df[,grep("t_statistic_",colnames(df), value=TRUE)]
colnames(ranks) <- sub("t_statistic_","",colnames(ranks))
ll = list()
for (i in unique(term2gene$Lipid_Class)){
  ll[[i]] = term2gene$lipid[term2gene$Lipid_Class==i]
}

for (i in 1:ncol(ranks)){
  print(colnames(ranks)[i])
  rank1 <- ranks[,i] %>% pull()
  names(rank1) = df$name
  fgsea::fgsea(ll,rank1) %>% arrange(pval) %>% print()
}
## [1] "X22RV1_PunA10 - X22RV1_PunA5"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      PE 0.04604317 0.6675697 0.25296112  0.6331415  1.4455158    23
##  2:      CE 0.13455657 0.6675697 0.21392786 -0.5261684 -1.2799392    19
##  3:      TG 0.13636364 0.6675697 0.27650060 -0.3709659 -1.1652914    71
##  4:      DG 0.17801858 0.6675697 0.12687573  0.6168463  1.2583043    13
##  5:      PG 0.29048843 0.7521008 0.12814292 -0.6146720 -1.2043045     8
##  6:  HexCer 0.30084034 0.7521008 0.09787733  0.7231008  1.1487494     4
##  7:      PI 0.43093093 0.7737342 0.07200331  0.4843955  1.0365309    17
##  8:    PC O 0.49099099 0.7737342 0.06553210  0.4649608  0.9949436    17
##  9:      PS 0.49388379 0.7737342 0.06613262  0.4909145  0.9937467    12
## 10:      SM 0.51582278 0.7737342 0.06568136  0.5162848  0.9769850     9
## 11:      PC 0.57803468 0.7882291 0.05594286  0.4039383  0.9251089    25
## 12:      CL 0.82293179 0.9832572 0.03992186  0.3289254  0.7626674    27
## 13:      FC 0.86868687 0.9832572 0.05258990  0.5555556  0.7585840     1
## 14:     Cer 0.97039474 0.9832572 0.03808421  0.2881184  0.5157964     7
## 15:    PE O 0.98325723 0.9832572 0.03382454  0.2573323  0.5490385    18
##      leadingEdge
##           <list>
##  1: PE 36:6,....
##  2: CE 22:3,....
##  3: TG 57:4,....
##  4: DG 36:3,....
##  5:      PG 40:7
##  6: HexCer 3....
##  7: PI 33:0,....
##  8: PC O-32:....
##  9: PS 34:1,....
## 10: SM 32:1;....
## 11: PC 36:6,....
## 12: CL 68:2,....
## 13:           FC
## 14: Cer 34:1....
## 15: PE O-36:....
## [1] "LNCaP_PunA10 - LNCaP_PunA5"
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      PS 0.0000264279 0.0003964185 0.57561026 -0.6911197 -2.5314119    12
##  2:      CL 0.0001296559 0.0009724191 0.51884808  0.6066332  1.8839582    27
##  3:     Cer 0.0005926738 0.0029633689 0.47727082  0.8130607  1.9026279     7
##  4:      DG 0.0014209013 0.0053283800 0.45505987 -0.5426357 -2.0429779    13
##  5:  HexCer 0.0159809059 0.0400265919 0.35248786 -0.7677903 -1.6867483     4
##  6:      PC 0.0160106368 0.0400265919 0.35248786  0.4915515  1.5110982    25
##  7:      PE 0.0335025381 0.0717911530 0.24891111  0.4907735  1.4908429    23
##  8:      TG 0.1490000000 0.2793750000 0.10925004  0.3469667  1.1878954    71
##  9:      CE 0.3615934627 0.6026557712 0.06170541  0.3661876  1.0785180    19
## 10:      SM 0.4850828729 0.7276243094 0.05163560  0.3947621  0.9859881     9
## 11:      FC 0.6047430830 0.7790041068 0.06879431 -0.7148148 -0.9459499     1
## 12:    PE O 0.6232032854 0.7790041068 0.03676196  0.3109289  0.9078533    18
## 13:    PC O 0.8436853002 0.9302587177 0.02179600  0.2562050  0.7355379    17
## 14:      PI 0.8995859213 0.9302587177 0.01778148  0.2323477  0.6670461    17
## 15:      PG 0.9302587177 0.9302587177 0.02092759  0.2535506  0.6118348     8
##      leadingEdge
##           <list>
##  1: PS 32:1,....
##  2: CL 70:7,....
##  3: Cer 42:1....
##  4: DG 36:5,....
##  5: HexCer 4....
##  6: PC 36:6,....
##  7: PE 36:6,....
##  8: TG 48:3,....
##  9: CE 18:3,....
## 10: SM 34:1;....
## 11:           FC
## 12: PE O-36:....
## 13: PC O-38:....
## 14: PI 33:0,....
## 15: PG 36:1,....
## [1] "PC3_PunA10 - PC3_PunA5"
##     pathway        pval      padj    log2err         ES        NES  size
##      <char>       <num>     <num>      <num>      <num>      <num> <int>
##  1:      TG 0.006097029 0.0793187 0.40701792  0.5984495  1.4202756    71
##  2:      PS 0.010575827 0.0793187 0.38073040 -0.6273195 -1.7521265    12
##  3:      DG 0.056581986 0.2785486 0.20207171  0.7088503  1.4170612    13
##  4:      PG 0.085556917 0.2785486 0.28780513 -0.5855513 -1.4186377     8
##  5:      CL 0.092849520 0.2785486 0.14826150  0.5968873  1.3218457    27
##  6:      PE 0.276387378 0.6744910 0.07829552  0.5351109  1.1611726    23
##  7:  HexCer 0.357377049 0.6744910 0.13077714 -0.5505618 -1.0989417     4
##  8:      PI 0.359728507 0.6744910 0.06689663  0.5373283  1.1171497    17
##  9:      CE 0.459579181 0.7659653 0.05423159  0.4932902  1.0492615    19
## 10:     Cer 0.660759494 0.9318182 0.04371258  0.4900302  0.8828160     7
## 11:    PE O 0.683333333 0.9318182 0.03614919  0.4169693  0.8807780    18
## 12:      SM 0.751507841 0.9322382 0.03554202  0.4138641  0.7891837     9
## 13:      PC 0.883172562 0.9322382 0.02114564  0.3108592  0.6833074    25
## 14:    PC O 0.915158371 0.9322382 0.02222678  0.2895461  0.6019901    17
## 15:      FC 0.932238193 0.9322382 0.05009229 -0.5370370 -0.7140758     1
##      leadingEdge
##           <list>
##  1: TG 50:6,....
##  2: PS 40:5,....
##  3: DG 40:6,....
##  4: PG 40:8,....
##  5: CL 56:3,....
##  6: PE 36:6,....
##  7: HexCer 4....
##  8: PI 33:0,....
##  9: CE 22:3,....
## 10: Cer 40:1....
## 11: PE O-36:....
## 12: SM 42:2;....
## 13: PC 36:6,....
## 14: PC O-36:....
## 15:           FC
## [1] "int_LNCaP_PunA10_PunA5"
##     pathway         pval        padj    log2err         ES        NES  size
##      <char>        <num>       <num>      <num>      <num>      <num> <int>
##  1:      TG 0.0002301273 0.003451909 0.51884808  0.5139198  1.6416738    71
##  2:      DG 0.0008606684 0.006455013 0.47727082 -0.5503876 -2.0130706    13
##  3:     Cer 0.0021593624 0.010796812 0.43170770  0.7961750  1.7625255     7
##  4:      PS 0.0042426702 0.015910013 0.40701792 -0.5200601 -1.8354057    12
##  5:      CL 0.0060833590 0.018250077 0.40701792  0.5355752  1.5734883    27
##  6:  HexCer 0.0709183181 0.177295795 0.28780513 -0.6666667 -1.4781027     4
##  7:      CE 0.1930745016 0.413731075 0.09624060  0.4369748  1.2075086    19
##  8:      PC 0.2615384615 0.490384615 0.07808923  0.3969829  1.1440441    25
##  9:      FC 0.6891891892 0.870011403 0.06130261 -0.6481481 -0.8776738     1
## 10:      PE 0.7079918033 0.870011403 0.03056081  0.3064005  0.8769002    23
## 11:      PG 0.7725674091 0.870011403 0.03287010  0.3416757  0.7810995     8
## 12:    PE O 0.7731092437 0.870011403 0.02737773  0.2999299  0.8204281    18
## 13:    PC O 0.8250790306 0.870011403 0.02407421  0.2822584  0.7641233    17
## 14:      PI 0.8387776607 0.870011403 0.02315383  0.2759757  0.7471151    17
## 15:      SM 0.8700114025 0.870011403 0.02548206  0.2959317  0.7004719     9
##      leadingEdge
##           <list>
##  1: TG 60:5,....
##  2: DG 34:2,....
##  3: Cer 42:1....
##  4: PS 34:1,....
##  5: CL 70:7,....
##  6: HexCer 4....
##  7: CE 22:3,....
##  8: PC 38:3,....
##  9:           FC
## 10: PE 36:4,....
## 11: PG 36:1,....
## 12: PE O-36:....
## 13: PC O-38:....
## 14: PI 33:0,....
## 15: SM 34:1;....
## [1] "int_PC3_PunA10_PunA5"
##     pathway        pval       padj    log2err         ES        NES  size
##      <char>       <num>      <num>      <num>      <num>      <num> <int>
##  1:      TG 0.004250279 0.06375419 0.40701792  0.5261124  1.5461360    71
##  2:      PS 0.013780186 0.10335139 0.38073040 -0.6693306 -1.6737990    12
##  3:      CL 0.032427601 0.16213801 0.32177592  0.5889977  1.5253923    27
##  4:      PE 0.150943396 0.56603774 0.22496609 -0.4313120 -1.2826618    23
##  5:      CE 0.316970547 0.93605547 0.08455574  0.4725717  1.1260073    19
##  6:  HexCer 0.456852792 0.93605547 0.09754492 -0.5374202 -0.9961369     4
##  7:      DG 0.468053492 0.93605547 0.06736239  0.4638120  1.0188832    13
##  8:    PC O 0.597972973 0.93605547 0.09854998 -0.3267717 -0.9005290    17
##  9:      PG 0.627300613 0.93605547 0.05490737  0.4499364  0.8905052     8
## 10:     Cer 0.651632970 0.93605547 0.05378728  0.4533622  0.8733892     7
## 11:      SM 0.686440678 0.93605547 0.08063885 -0.3475621 -0.8119522     9
## 12:      FC 0.819253438 0.96742210 0.05400883 -0.5814815 -0.7823204     1
## 13:      PC 0.841698842 0.96742210 0.08653997 -0.2476985 -0.7570231    25
## 14:    PE O 0.938375350 0.96742210 0.03207042  0.2555041  0.6058603    18
## 15:      PI 0.967422096 0.96742210 0.03113351  0.2366085  0.5534791    17
##      leadingEdge
##           <list>
##  1: TG 53:1,....
##  2: PS 34:1,....
##  3: CL 56:3,....
##  4: PE 36:6,....
##  5: CE 22:3,....
##  6: HexCer 4....
##  7: DG 36:1,....
##  8: PC O-32:....
##  9: PG 40:7,....
## 10: Cer 40:1....
## 11: SM 32:1;....
## 12:           FC
## 13: PC 38:5,....
## 14: PE O-40:....
## 15: PI 36:4,....

2.7 PunA 2.5 vs PunA 10

cdt1 <- "PunA10"
cdt2 <- "PunA2.5"

2.7.1 DEA

res <- merge_res_prostate(append = TRUE)

pander("all the lipids")

all the lipids

res$p_VP

ggplotly(res$p_VP)
pander("only lipids not totally missing in ome condition")

only lipids not totally missing in ome condition

res$p_VP2

ggplotly(res$p_VP2)
pander("upregulated")

upregulated

if(sum(colSums(res$us_pos)>0)>1){
  UpSetR::upset(as.data.frame(res$us_pos), 
                keep.order = TRUE, nsets = ncol(res$us_pos)) %>%
    print()
}

pander("downregulated")

downregulated

if(sum(colSums(res$us_neg)>0)>1){
  UpSetR::upset(as.data.frame(res$us_neg), 
                keep.order = TRUE, nsets = ncol(res$us_neg)) %>%
    print()
}

#### heatmaps
ht_fun()
## [[1]]

## 
## [[2]]

## 
## [[3]]

2.7.2 GSEA

pander("GSEA")

GSEA

df = res$df_all_wide
ranks <- df[,grep("t_statistic_",colnames(df), value=TRUE)]
colnames(ranks) <- sub("t_statistic_","",colnames(ranks))
ll = list()
for (i in unique(term2gene$Lipid_Class)){
  ll[[i]] = term2gene$lipid[term2gene$Lipid_Class==i]
}

for (i in 1:ncol(ranks)){
  print(colnames(ranks)[i])
  rank1 <- ranks[,i] %>% pull()
  names(rank1) = df$name
  fgsea::fgsea(ll,rank1) %>% arrange(pval) %>% print()
}
## [1] "X22RV1_PunA10 - X22RV1_PunA2.5"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      DG 0.02740575 0.3226300 0.35248786  0.7732116  1.4949251    13
##  2:      CE 0.04301733 0.3226300 0.32177592 -0.6114447 -1.5250312    19
##  3:      PE 0.13731343 0.5978261 0.14375899  0.6001651  1.3186407    23
##  4:      PC 0.15942029 0.5978261 0.13010563  0.5731926  1.2879251    25
##  5:      TG 0.28641975 0.8557348 0.08312913  0.4333582  1.1173418    71
##  6:      SM 0.34229391 0.8557348 0.09405035  0.6148086  1.1209480     9
##  7:      PI 0.48661417 0.9701671 0.06831109  0.4828796  0.9977994    17
##  8:      PG 0.52808989 0.9701671 0.08243441 -0.5009029 -0.9819042     8
##  9:    PC O 0.61852861 0.9701671 0.08431443 -0.3667234 -0.8828480    17
## 10:      PS 0.64677804 0.9701671 0.07492788 -0.3899754 -0.8620031    12
## 11:      FC 0.72000000 0.9768212 0.06090393  0.6407407  0.8638488     1
## 12:      CL 0.78145695 0.9768212 0.08220549 -0.3143448 -0.8401887    27
## 13:  HexCer 0.87550201 0.9810427 0.05195125 -0.4078310 -0.6886026     4
## 14:     Cer 0.95596330 0.9810427 0.04380020  0.2878788  0.5057712     7
## 15:    PE O 0.98104265 0.9810427 0.03569331  0.2379388  0.4937560    18
##      leadingEdge
##           <list>
##  1: DG 36:3,....
##  2: CE 22:4,....
##  3: PE 36:6,....
##  4: PC 36:6,....
##  5: TG 50:6,....
##  6: SM 41:1;....
##  7: PI 33:0,....
##  8: PG 36:2,....
##  9: PC O-34:....
## 10: PS 36:2,....
## 11:           FC
## 12: CL 74:9,....
## 13: HexCer 4....
## 14: Cer 34:1....
## 15: PE O-32:....
## [1] "LNCaP_PunA10 - LNCaP_PunA2.5"
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      TG 7.155452e-06 0.0001073318 0.61052688  0.7937091  1.4516776    71
##  2:      PE 1.764092e-01 0.9908735332 0.10135074  0.6969108  1.2236432    23
##  3:      PS 3.203991e-01 0.9908735332 0.07165274  0.6864148  1.1476218    12
##  4:      PC 3.601651e-01 0.9908735332 0.06238615  0.6246642  1.1037790    25
##  5:      CE 3.849417e-01 0.9908735332 0.06050930  0.6347571  1.1040608    19
##  6:      PG 5.095541e-01 0.9908735332 0.15524197 -0.3802281 -0.9211616     8
##  7:     Cer 5.119617e-01 0.9908735332 0.05280500  0.6278543  1.0113647     7
##  8:      SM 7.025463e-01 0.9908735332 0.03676196  0.5211008  0.8497804     9
##  9:    PC O 7.813853e-01 0.9908735332 0.02836285  0.4677294  0.8015363    17
## 10:      FC 8.483685e-01 0.9908735332 0.05132233  0.5925926  0.7764019     1
## 11:      PI 8.787879e-01 0.9908735332 0.02201165  0.3845751  0.6590369    17
## 12:    PE O 9.023605e-01 0.9908735332 0.01990018  0.3650860  0.6299736    18
## 13:      DG 9.117971e-01 0.9908735332 0.02092759  0.3538809  0.5958892    13
## 14:      CL 9.804325e-01 0.9908735332 0.01035046  0.2778620  0.4939179    27
## 15:  HexCer 9.908735e-01 0.9908735332 0.02569275  0.3018858  0.4539483     4
##      leadingEdge
##           <list>
##  1: TG 50:6,....
##  2: PE 36:6,....
##  3: PS 40:2,....
##  4: PC 36:6,....
##  5: CE 18:3,....
##  6: PG 40:7,....
##  7: Cer 34:1....
##  8: SM 41:1;....
##  9: PC O-36:....
## 10:           FC
## 11: PI 38:6,....
## 12: PE O-34:....
## 13: DG 36:4,....
## 14: CL 70:7,....
## 15: HexCer 3....
## [1] "PC3_PunA10 - PC3_PunA2.5"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      TG 0.02862986 0.2916192 0.27128855  0.6299885  1.3486739    71
##  2:      DG 0.03888256 0.2916192 0.32177592  0.7990657  1.4495970    13
##  3:      PS 0.11673152 0.5732205 0.26166352 -0.6182647 -1.3721205    12
##  4:      PC 0.15285881 0.5732205 0.11776579  0.6376858  1.2693041    25
##  5:      PG 0.22121212 0.6636364 0.16318013 -0.6108197 -1.2532315     8
##  6:      PE 0.35335689 0.8833922 0.06977925  0.5667765  1.1152909    23
##  7:      CE 0.56127451 0.9852941 0.04969014  0.4971894  0.9547910    19
##  8:      PI 0.66040100 0.9852941 0.04327687  0.4644897  0.8816940    17
##  9:      CL 0.76064442 0.9852941 0.03272419  0.4047967  0.8112092    27
## 10:      SM 0.81037037 0.9852941 0.04157179  0.4274809  0.7321813     9
## 11:  HexCer 0.87979094 0.9852941 0.04522474  0.4307116  0.6602691     4
## 12:      FC 0.91752577 0.9852941 0.05101141  0.5333333  0.7181527     1
## 13:    PE O 0.92346939 0.9852941 0.09721508 -0.2529644 -0.6486099    18
## 14:     Cer 0.96788991 0.9852941 0.03479041  0.2962148  0.4925741     7
## 15:    PC O 0.98529412 0.9852941 0.09110731 -0.2007874 -0.5074900    17
##      leadingEdge
##           <list>
##  1: TG 54:7,....
##  2: DG 38:4,....
##  3: PS 40:5,....
##  4: PC 36:6,....
##  5: PG 34:1,....
##  6: PE 36:6,....
##  7: CE 18:3,....
##  8: PI 33:0,....
##  9: CL 72:11....
## 10: SM 41:1;....
## 11: HexCer 3....
## 12:           FC
## 13: PE O-40:....
## 14: Cer 40:1....
## 15: PC O-40:....
## [1] "int_LNCaP_PunA10_PunA2.5"
##     pathway         pval        padj    log2err         ES        NES  size
##      <char>        <num>       <num>      <num>      <num>      <num> <int>
##  1:      DG 0.0004708108 0.007062162 0.49849311 -0.7812177 -1.9842108    13
##  2:      TG 0.0020919566 0.012230566 0.43170770  0.5137722  1.5803462    71
##  3:      CE 0.0024461131 0.012230566 0.43170770  0.7080947  1.7228821    19
##  4:    PC O 0.2376373626 0.891140110 0.09992770  0.5122230  1.2087106    17
##  5:      PS 0.4102209945 0.957295035 0.07028128  0.4780539  1.0668702    12
##  6:      PI 0.5036496350 0.957295035 0.11426650 -0.3556758 -0.9780662    17
##  7:      PG 0.5563480742 0.957295035 0.05712585  0.4837988  0.9644265     8
##  8:     Cer 0.6521739130 0.957295035 0.05049830  0.4614737  0.8869278     7
##  9:      SM 0.7384105960 0.957295035 0.08528847 -0.3319832 -0.7743484     9
## 10:      FC 0.8146551724 0.957295035 0.05859376 -0.5851852 -0.7885778     1
## 11:    PE O 0.8208955224 0.957295035 0.08603472 -0.2759340 -0.7792920    18
## 12:      PC 0.8427419355 0.957295035 0.08889453 -0.2490994 -0.7606706    25
## 13:  HexCer 0.8571428571 0.957295035 0.07182763 -0.3595506 -0.6744654     4
## 14:      PE 0.8934753662 0.957295035 0.03199805  0.2671823  0.6809261    23
## 15:      CL 0.9960369881 0.996036988 0.02611396  0.1779512  0.4716567    27
##      leadingEdge
##           <list>
##  1: DG 36:3,....
##  2: TG 57:4,....
##  3: CE 22:4,....
##  4: PC O-36:....
##  5: PS 36:2,....
##  6:      PI 33:0
##  7: PG 36:2,....
##  8: Cer 42:2....
##  9: SM 41:2;....
## 10:           FC
## 11: PE O-32:....
## 12: PC 38:5,....
## 13: HexCer 4....
## 14: PE 36:4,....
## 15: CL 70:7,....
## [1] "int_PC3_PunA10_PunA2.5"
##     pathway        pval       padj    log2err         ES        NES  size
##      <char>       <num>      <num>      <num>      <num>      <num> <int>
##  1:      CE 0.004757594 0.07136391 0.40701792  0.7400766  1.6489872    19
##  2:      PE 0.028682525 0.18564356 0.35248786 -0.5648697 -1.5262576    23
##  3:      TG 0.037128713 0.18564356 0.26166352  0.5001878  1.3777776    71
##  4:      SM 0.185000000 0.69375000 0.16197895 -0.6013221 -1.3030862     9
##  5:      PS 0.236559140 0.70967742 0.14733121 -0.5169142 -1.1876109    12
##  6:      CL 0.336661912 0.84165478 0.08220549  0.4580775  1.0967063    27
##  7:     Cer 0.534109817 0.92953930 0.06643641  0.5177195  0.9525866     7
##  8:      PC 0.583333333 0.92953930 0.09688777 -0.3433671 -0.9308295    25
##  9:    PC O 0.734824281 0.92953930 0.04949049  0.3770094  0.8200496    17
## 10:    PE O 0.764542936 0.92953930 0.07399014 -0.3175755 -0.8093322    18
## 11:      PI 0.779255319 0.92953930 0.07096095 -0.3104145 -0.7900577    17
## 12:      FC 0.844230769 0.92953930 0.05163560 -0.5851852 -0.7824544     1
## 13:  HexCer 0.915331808 0.92953930 0.05594286 -0.3224888 -0.5673245     4
## 14:      PG 0.917922948 0.92953930 0.04148804  0.3269962  0.6145817     8
## 15:      DG 0.929539295 0.92953930 0.06321912 -0.2780362 -0.6510141    13
##      leadingEdge
##           <list>
##  1: CE 22:3,....
##  2: PE 34:3,....
##  3: TG 53:1,....
##  4: SM 41:1;....
##  5: PS 40:5,....
##  6: CL 72:11....
##  7: Cer 40:1....
##  8: PC 40:8,....
##  9: PC O-36:....
## 10: PE O-32:....
## 11: PI 40:5,....
## 12:           FC
## 13: HexCer 4....
## 14: PG 36:0,....
## 15: DG 36:3,....

2.8 CTL vs Fer1_3

cdt1 <- "Fer1_3"
cdt2 <- "Control"

2.8.1 DEA

res <- merge_res_prostate(append = TRUE)

pander("all the lipids")

all the lipids

res$p_VP

ggplotly(res$p_VP)
pander("only lipids not totally missing in ome condition")

only lipids not totally missing in ome condition

res$p_VP2

ggplotly(res$p_VP2)
pander("upregulated")

upregulated

if(sum(colSums(res$us_pos)>0)>1){
  UpSetR::upset(as.data.frame(res$us_pos), 
                keep.order = TRUE, nsets = ncol(res$us_pos)) %>%
    print()
}
pander("downregulated")

downregulated

if(sum(colSums(res$us_neg)>0)>1){
  UpSetR::upset(as.data.frame(res$us_neg), 
                keep.order = TRUE, nsets = ncol(res$us_neg)) %>%
    print()
}

#### heatmaps
ht_fun()
## [[1]]

## 
## [[2]]

## 
## [[3]]

2.8.2 GSEA

pander("GSEA")

GSEA

df = res$df_all_wide
ranks <- df[,grep("t_statistic_",colnames(df), value=TRUE)]
colnames(ranks) <- sub("t_statistic_","",colnames(ranks))
ll = list()
for (i in unique(term2gene$Lipid_Class)){
  ll[[i]] = term2gene$lipid[term2gene$Lipid_Class==i]
}

for (i in 1:ncol(ranks)){
  print(colnames(ranks)[i])
  rank1 <- ranks[,i] %>% pull()
  names(rank1) = df$name
  fgsea::fgsea(ll,rank1) %>% arrange(pval) %>% print()
}
## [1] "X22RV1_Fer1_3 - X22RV1_Control"
## Warning in fgseaMultilevel(pathways = pathways, stats = stats, minSize =
## minSize, : There were 1 pathways for which P-values were not calculated
## properly due to unbalanced (positive and negative) gene-level statistic values.
## For such pathways pval, padj, NES, log2err are set to NA. You can try to
## increase the value of the argument nPermSimple (for example set it nPermSimple
## = 10000)
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      PE 2.795299e-05 0.0003913419 0.57561026 -0.6665788 -1.9235402    23
##  2:      PC 4.038910e-03 0.0282723709 0.40701792 -0.5502086 -1.6171011    25
##  3:    PE O 1.381821e-02 0.0611559140 0.38073040 -0.5452961 -1.5172941    18
##  4:     Cer 2.177677e-02 0.0611559140 0.35248786 -0.6988921 -1.5662568     7
##  5:  HexCer 2.577807e-02 0.0611559140 0.35248786  0.7490637  1.6406582     4
##  6:      CL 2.620968e-02 0.0611559140 0.28201335 -0.4936695 -1.4690734    27
##  7:      PI 8.263598e-02 0.1652719665 0.15631240 -0.4905453 -1.3466242    17
##  8:      PG 1.539326e-01 0.2693820225 0.11475072 -0.5451488 -1.2730257     8
##  9:      PS 3.117479e-01 0.4849411330 0.20350896  0.3043776  1.1070416    12
## 10:      SM 5.593407e-01 0.7830769231 0.04486451 -0.3922466 -0.9472588     9
## 11:      DG 6.666667e-01 0.8257161249 0.03516523 -0.3360732 -0.8794835    13
## 12:      CE 7.373841e-01 0.8257161249 0.02878615 -0.2992775 -0.8415487    19
## 13:    PC O 7.667364e-01 0.8257161249 0.02758859 -0.3023988 -0.8301324    17
## 14:      FC 8.789062e-01 0.8789062500 0.05049830  0.5629630  0.7513470     1
## 15:      TG           NA           NA         NA  0.3555144         NA    71
##      leadingEdge
##           <list>
##  1: PE 36:4,....
##  2: PC 36:3,....
##  3: PE O-40:....
##  4: Cer 42:2....
##  5: HexCer 4....
##  6: CL 70:6,....
##  7: PI 36:4,....
##  8: PG 34:0,....
##  9: PS 38:0,....
## 10: SM 34:1;....
## 11: DG 36:4,....
## 12: CE 22:6,....
## 13: PC O-36:....
## 14:           FC
## 15: TG 60:5,....
## [1] "LNCaP_Fer1_3 - LNCaP_Control"
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      TG 3.603590e-19 5.405385e-18 1.13308993  0.8304835  2.5282813    71
##  2:      PE 1.667790e-04 1.250842e-03 0.51884808 -0.7785036 -1.9030562    23
##  3:      DG 6.701139e-03 3.350569e-02 0.40701792 -0.8065339 -1.7755818    13
##  4:  HexCer 1.473684e-01 5.526316e-01 0.18820415 -0.7722596 -1.4459316     4
##  5:      SM 2.485549e-01 7.456647e-01 0.14920754 -0.6199468 -1.2732483     9
##  6:      CE 2.989045e-01 7.472613e-01 0.09405035  0.4730384  1.1345176    19
##  7:    PE O 5.079787e-01 9.443489e-01 0.09405035 -0.4144005 -0.9776109    18
##  8:     Cer 5.878788e-01 9.443489e-01 0.05736674  0.4828838  0.9383108     7
##  9:      PG 6.548673e-01 9.443489e-01 0.08553569 -0.4024174 -0.8116003     8
## 10:    PC O 7.727273e-01 9.443489e-01 0.07165274 -0.3146788 -0.7386052    17
## 11:      FC 7.762646e-01 9.443489e-01 0.05605959  0.6148148  0.8355049     1
## 12:      PS 7.860465e-01 9.443489e-01 0.04504428  0.3529297  0.7705068    12
## 13:      CL 8.184358e-01 9.443489e-01 0.07096095 -0.2971740 -0.7497634    27
## 14:      PC 8.948787e-01 9.587986e-01 0.06479434 -0.2697317 -0.6718621    25
## 15:      PI 9.824841e-01 9.824841e-01 0.03599689  0.2086614  0.4904916    17
##      leadingEdge
##           <list>
##  1: TG 48:0,....
##  2: PE 34:3,....
##  3: DG 34:2,....
##  4: HexCer 3....
##  5: SM 41:2;....
##  6: CE 18:3,....
##  7: PE O-36:....
##  8: Cer 42:1....
##  9: PG 40:7,....
## 10: PC O-38:....
## 11:           FC
## 12: PS 36:3,....
## 13:      CL 70:7
## 14: PC 34:4,....
## 15: PI 38:6,....
## [1] "PC3_Fer1_3 - PC3_Control"
##     pathway       pval      padj    log2err         ES        NES  size
##      <char>      <num>     <num>      <num>      <num>      <num> <int>
##  1:      PI 0.03248260 0.2348993 0.27128855 -0.5623084 -1.4620240    17
##  2:     Cer 0.03832335 0.2348993 0.25296112 -0.6762365 -1.4511001     7
##  3:      PE 0.04697987 0.2348993 0.21925035 -0.5088131 -1.4091087    23
##  4:      CE 0.12086659 0.4532497 0.13284630 -0.4833955 -1.2833361    19
##  5:  HexCer 0.21875000 0.6464800 0.20207171  0.6067416  1.2057143     4
##  6:      PC 0.26415094 0.6464800 0.08175156 -0.4085900 -1.1539561    25
##  7:      SM 0.31672598 0.6464800 0.07569463 -0.4874928 -1.1008825     9
##  8:      CL 0.34478936 0.6464800 0.06799226 -0.3832587 -1.0936725    27
##  9:    PC O 0.58932715 0.9693718 0.04495431 -0.3596929 -0.9352158    17
## 10:      PG 0.71770335 0.9693718 0.03730298 -0.3853630 -0.8468303     8
## 11:    PE O 0.73156682 0.9693718 0.03464102 -0.3258227 -0.8561621    18
## 12:      FC 0.78685259 0.9693718 0.05652995  0.6111111  0.8213115     1
## 13:      TG 0.84012220 0.9693718 0.02107303 -0.2356512 -0.7792338    71
## 14:      DG 0.96871379 0.9918605 0.02026911 -0.2403245 -0.5879715    13
## 15:      PS 0.99186047 0.9918605 0.01900420 -0.2066719 -0.4955581    12
##      leadingEdge
##           <list>
##  1: PI 38:4,....
##  2: Cer 42:2....
##  3: PE 36:1,....
##  4: CE 20:0,....
##  5: HexCer 4....
##  6: PC 30:0,....
##  7: SM 41:2;....
##  8: CL 70:6,....
##  9: PC O-36:....
## 10: PG 34:1,....
## 11: PE O-40:....
## 12:           FC
## 13: TG 55:5,....
## 14: DG 38:5,....
## 15:      PS 36:2
## [1] "int_LNCaP_Fer1_3_Control"
##     pathway        pval       padj    log2err         ES        NES  size
##      <char>       <num>      <num>      <num>      <num>      <num> <int>
##  1:     Cer 0.004465064 0.03853645 0.40701792  0.7173976  1.6590276     7
##  2:  HexCer 0.005138193 0.03853645 0.40701792 -0.8539326 -1.8532582     4
##  3:    PE O 0.012671673 0.06335836 0.38073040  0.5281990  1.5741765    18
##  4:      PC 0.029787234 0.11170213 0.27128855  0.4617002  1.4856800    25
##  5:      PE 0.163499645 0.49049893 0.24924655 -0.2765705 -1.2486409    23
##  6:      PI 0.233223322 0.58305831 0.08809450  0.4064524  1.1916632    17
##  7:      CL 0.273594910 0.58627481 0.07747675  0.3518093  1.1438294    27
##  8:      PG 0.417582418 0.78296703 0.06335970  0.4331415  1.0349802     8
##  9:      TG 0.516194332 0.86032389 0.04477489  0.2643140  0.9905761    71
## 10:      CE 0.668484188 0.90887290 0.03630185  0.2928067  0.8811959    19
## 11:      DG 0.722222222 0.90887290 0.14463053 -0.2223492 -0.8300776    13
## 12:      PS 0.837037037 0.90887290 0.12814292 -0.2098846 -0.7516570    12
## 13:      FC 0.880808081 0.90887290 0.05195125 -0.5629630 -0.7598923     1
## 14:    PC O 0.887788779 0.90887290 0.02236993  0.2345392  0.6876369    17
## 15:      SM 0.908872902 0.90887290 0.02583317  0.2733986  0.6770148     9
##      leadingEdge
##           <list>
##  1: Cer 42:2....
##  2: HexCer 4....
##  3: PE O-40:....
##  4: PC 32:0,....
##  5: PE 34:3,....
##  6: PI 36:4,....
##  7: CL 74:8,....
##  8: PG 34:0,....
##  9: TG 50:3,....
## 10: CE 22:6,....
## 11: DG 36:3,....
## 12: PS 38:2,....
## 13:           FC
## 14: PC O-40:....
## 15: SM 36:1;....
## [1] "int_PC3_Fer1_3_Control"
##     pathway        pval      padj    log2err         ES        NES  size
##      <char>       <num>     <num>      <num>      <num>      <num> <int>
##  1:      CE 0.003615347 0.0542302 0.43170770 -0.6538543 -1.8244952    19
##  2:  HexCer 0.020615374 0.1546153 0.35248786 -0.8801498 -1.5628306     4
##  3:      PS 0.071611253 0.3580563 0.27128855 -0.5931533 -1.4531728    12
##  4:      CL 0.126878130 0.4757930 0.15964670  0.4714966  1.2989971    27
##  5:      PC 0.243506494 0.5809979 0.10882013  0.4274887  1.1670458    25
##  6:      DG 0.260229133 0.5809979 0.10512513  0.4964400  1.1681965    13
##  7:      TG 0.271132376 0.5809979 0.10099059  0.3308976  1.1151752    71
##  8:    PE O 0.432835821 0.7753759 0.07687367  0.4041464  1.0306591    18
##  9:      PG 0.515248796 0.7753759 0.06643641  0.4747103  0.9842550     8
## 10:      PE 0.518151815 0.7753759 0.06751890  0.3658493  0.9773946    23
## 11:     Cer 0.572567783 0.7753759 0.06103637  0.4672571  0.9389868     7
## 12:      SM 0.656992084 0.7753759 0.07934350 -0.3871494 -0.8728949     9
## 13:      PI 0.703947368 0.7753759 0.05280500  0.3311355  0.8331472    17
## 14:    PC O 0.723684211 0.7753759 0.05153091  0.3214479  0.8087726    17
## 15:      FC 0.828629032 0.8286290 0.05468085  0.5814815  0.7870113     1
##      leadingEdge
##           <list>
##  1: CE 20:0,....
##  2: HexCer 4....
##  3: PS 38:0,....
##  4: CL 68:5,....
##  5: PC 40:5,....
##  6: DG 36:4,....
##  7: TG 53:4,....
##  8: PE O-40:....
##  9: PG 36:0,....
## 10: PE 36:6,....
## 11: Cer 42:2....
## 12: SM 41:2;....
## 13: PI 40:5,....
## 14: PC O-38:....
## 15:           FC

2.9 PunA 10 vs Fer1 - PunA 10

cdt1 <- "PunA10_fer13"
cdt2 <- "PunA10"

2.9.1 DEA

res <- merge_res_prostate(append = TRUE)

pander("all the lipids")

all the lipids

res$p_VP

ggplotly(res$p_VP)
pander("only lipids not totally missing in ome condition")

only lipids not totally missing in ome condition

res$p_VP2

ggplotly(res$p_VP2)
pander("upregulated")

upregulated

if(sum(colSums(res$us_pos)>0)>1){
  UpSetR::upset(as.data.frame(res$us_pos), 
                keep.order = TRUE, nsets = ncol(res$us_pos)) %>%
    print()
}
pander("downregulated")

downregulated

if(sum(colSums(res$us_neg)>0)>1){
  UpSetR::upset(as.data.frame(res$us_neg), 
                keep.order = TRUE, nsets = ncol(res$us_neg)) %>%
    print()
}

#### heatmaps
ht_fun()
## [[1]]

## 
## [[2]]

## 
## [[3]]

2.9.2 GSEA

pander("GSEA")

GSEA

df = res$df_all_wide
ranks <- df[,grep("t_statistic_",colnames(df), value=TRUE)]
colnames(ranks) <- sub("t_statistic_","",colnames(ranks))
ll = list()
for (i in unique(term2gene$Lipid_Class)){
  ll[[i]] = term2gene$lipid[term2gene$Lipid_Class==i]
}

for (i in 1:ncol(ranks)){
  print(colnames(ranks)[i])
  rank1 <- ranks[,i] %>% pull()
  names(rank1) = df$name
  fgsea::fgsea(ll,rank1) %>% arrange(pval) %>% print()
}
## [1] "X22RV1_PunA10_fer13 - X22RV1_PunA10"
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      TG 1.528555e-21 2.292833e-20 1.20397524  0.8429649  2.4058946    71
##  2:    PC O 1.054313e-02 7.907346e-02 0.38073040 -0.4922661 -1.7109521    17
##  3:      PC 3.796123e-02 1.898062e-01 0.32177592 -0.3455285 -1.3351384    25
##  4:      CE 1.079607e-01 4.048528e-01 0.13802224  0.5355880  1.3098422    19
##  5:  HexCer 1.548673e-01 4.646018e-01 0.24133998 -0.6709163 -1.3354546     4
##  6:      CL 2.877336e-01 7.193339e-01 0.20350896 -0.2622951 -1.0461406    27
##  7:    PE O 4.470588e-01 8.682159e-01 0.23112671 -0.2806324 -0.9913283    18
##  8:      SM 4.630485e-01 8.682159e-01 0.05582647  0.4815437  1.0171304     9
##  9:      FC 5.268595e-01 8.780992e-01 0.07808923 -0.7222222 -0.9840356     1
## 10:      PI 7.690608e-01 9.316272e-01 0.03020419  0.3437652  0.8166675    17
## 11:     Cer 7.863962e-01 9.316272e-01 0.03287010  0.3982315  0.7926673     7
## 12:      PS 8.206583e-01 9.316272e-01 0.02829237  0.3440827  0.7653729    12
## 13:      DG 8.605442e-01 9.316272e-01 0.02576296  0.3250150  0.7307851    13
## 14:      PE 8.695187e-01 9.316272e-01 0.02193983  0.2895713  0.7298580    23
## 15:      PG 9.662398e-01 9.662398e-01 0.02070884  0.2909997  0.6000948     8
##      leadingEdge
##           <list>
##  1: TG 48:2,....
##  2: PC O-30:....
##  3: PC 38:5,....
##  4: CE 20:5,....
##  5: HexCer 4....
##  6: CL 76:4,....
##  7: PE O-32:....
##  8: SM 41:2;....
##  9:           FC
## 10: PI 34:2,....
## 11: Cer 42:1....
## 12: PS 36:2,....
## 13: DG 40:5,....
## 14: PE 36:5,....
## 15: PG 32:0,....
## [1] "LNCaP_PunA10_fer13 - LNCaP_PunA10"
##     pathway         pval         padj    log2err         ES        NES  size
##      <char>        <num>        <num>      <num>      <num>      <num> <int>
##  1:      TG 2.113598e-09 3.170397e-08 0.77493903  0.6531756  2.1964851    71
##  2:  HexCer 2.555277e-03 1.916457e-02 0.43170770 -0.9548295 -1.8651958     4
##  3:    PC O 9.258866e-03 4.629433e-02 0.38073040 -0.5792338 -1.7369066    17
##  4:      PE 1.045590e-01 3.920963e-01 0.28780513 -0.3951613 -1.3465371    23
##  5:      PC 1.971154e-01 4.953476e-01 0.22205605 -0.3500679 -1.2040632    25
##  6:      DG 2.142857e-01 4.953476e-01 0.20429476 -0.4263566 -1.1991661    13
##  7:    PE O 2.311622e-01 4.953476e-01 0.09721508  0.4650135  1.1879189    18
##  8:      CL 3.612824e-01 6.647673e-01 0.07096095  0.3813376  1.0814624    27
##  9:      PI 4.783163e-01 6.647673e-01 0.05896945  0.3920324  0.9945868    17
## 10:      CE 5.137615e-01 6.647673e-01 0.12878871 -0.3148406 -0.9743227    19
## 11:      SM 5.208877e-01 6.647673e-01 0.05605959  0.4484395  0.9810825     9
## 12:      FC 5.702306e-01 6.647673e-01 0.07473852 -0.7074074 -0.9499211     1
## 13:     Cer 5.761317e-01 6.647673e-01 0.11331291 -0.3939394 -0.9005333     7
## 14:      PS 7.142857e-01 7.221494e-01 0.10282184 -0.2909409 -0.8093876    12
## 15:      PG 7.221494e-01 7.221494e-01 0.04123761  0.3927836  0.8335889     8
##      leadingEdge
##           <list>
##  1: TG 48:0,....
##  2: HexCer 3....
##  3: PC O-38:....
##  4: PE 36:4,....
##  5: PC 40:8,....
##  6: DG 36:4,....
##  7: PE O-36:....
##  8: CL 72:11....
##  9: PI 36:2,....
## 10: CE 20:1,....
## 11: SM 41:2;....
## 12:           FC
## 13: Cer 36:1....
## 14: PS 38:0,....
## 15: PG 36:0,....
## [1] "PC3_PunA10_fer13 - PC3_PunA10"
##     pathway        pval       padj     log2err         ES        NES  size
##      <char>       <num>      <num>       <num>      <num>      <num> <int>
##  1:      PE 0.002206284 0.03309425 0.431707696 -0.5871879 -1.6785058    23
##  2:      DG 0.035012436 0.12182741 0.321775918 -0.5853422 -1.5403146    13
##  3:  HexCer 0.035888786 0.12182741 0.321775918  0.6891386  1.4952074     4
##  4:      CE 0.041067762 0.12182741 0.224966094 -0.5119030 -1.4273836    19
##  5:      SM 0.044516830 0.12182741 0.222056046 -0.5981739 -1.4504319     9
##  6:      PC 0.048730964 0.12182741 0.204294757 -0.4763114 -1.3761175    25
##  7:    PE O 0.086508754 0.18537590 0.151148761 -0.4804247 -1.3311464    18
##  8:      PS 0.142172746 0.26657390 0.249246554  0.3513514  1.2803374    12
##  9:     Cer 0.285554311 0.42943548 0.078089231 -0.5001018 -1.1420579     7
## 10:      CL 0.286290323 0.42943548 0.072535186 -0.3822253 -1.1186197    27
## 11:    PC O 0.674586777 0.88153340 0.033309282 -0.3216639 -0.8847136    17
## 12:      FC 0.715725806 0.88153340 0.061570676  0.6407407  0.8689321     1
## 13:      PG 0.763995609 0.88153340 0.030204195 -0.3418596 -0.8075474     8
## 14:      TG 0.963036963 0.99070248 0.008938012 -0.2214872 -0.7032335    71
## 15:      PI 0.990702479 0.99070248 0.009547607 -0.1854119 -0.5099620    17
##      leadingEdge
##           <list>
##  1: PE 36:1,....
##  2: DG 34:1,....
##  3: HexCer 4....
##  4: CE 22:5,....
##  5: SM 36:1;....
##  6: PC 38:4,....
##  7: PE O-36:....
##  8: PS 40:5,....
##  9: Cer 40:1....
## 10: CL 72:3,....
## 11: PC O-36:....
## 12:           FC
## 13: PG 34:1,....
## 14: TG 53:1,....
## 15: PI 40:4,....
## [1] "int_LNCaP_PunA10_fer13_PunA10"
##     pathway         pval       padj    log2err         ES        NES  size
##      <char>        <num>      <num>      <num>      <num>      <num> <int>
##  1:      TG 0.0009389503 0.01408425 0.47727082 -0.5454651 -1.6368469    71
##  2:      CE 0.0614250614 0.46068796 0.19991523 -0.5793783 -1.4279282    19
##  3:    PC O 0.2536945813 0.79827602 0.08971047 -0.4900690 -1.1771583    17
##  4:      CL 0.2597402597 0.79827602 0.22496609  0.3070716  1.1096552    27
##  5:      SM 0.2828418231 0.79827602 0.08835944 -0.5548198 -1.1624671     9
##  6:      PS 0.4750000000 0.79827602 0.12750532  0.3466578  0.9963594    12
##  7:    PE O 0.5025641026 0.79827602 0.13880511  0.3030956  0.9760878    18
##  8:  HexCer 0.5318471338 0.79827602 0.10208011  0.4768318  0.9195012     4
##  9:      PI 0.5421052632 0.79827602 0.13500203  0.3110236  0.9738083    17
## 10:      FC 0.5431372549 0.79827602 0.07380527  0.7259259  0.9723018     1
## 11:      DG 0.6308290155 0.79827602 0.04688199 -0.3939988 -0.8921602    13
## 12:     Cer 0.6395027624 0.79827602 0.04919275 -0.4513560 -0.8878220     7
## 13:      PE 0.6918392205 0.79827602 0.03984069 -0.3309292 -0.8465634    23
## 14:      PC 0.9587878788 0.98378378 0.02350848 -0.2196950 -0.5713662    25
## 15:      PG 0.9837837838 0.98378378 0.02794028 -0.2413391 -0.4931316     8
##      leadingEdge
##           <list>
##  1: TG 57:4,....
##  2: CE 20:5,....
##  3: PC O-38:....
##  4: CL 76:4,....
##  5: SM 40:2;....
##  6: PS 32:1,....
##  7: PE O-32:....
##  8: HexCer 4....
##  9: PI 34:0,....
## 10:           FC
## 11: DG 40:5,....
## 12: Cer 42:1....
## 13: PE 36:5,....
## 14: PC 38:3,....
## 15: PG 32:0,....
## [1] "int_PC3_PunA10_fer13_PunA10"
##     pathway        pval       padj    log2err         ES        NES  size
##      <char>       <num>      <num>      <num>      <num>      <num> <int>
##  1:      TG 0.003052349 0.04578524 0.43170770 -0.4617136 -1.4147614    71
##  2:      CE 0.077235772 0.47242084 0.15964670 -0.4911780 -1.3277904    19
##  3:      SM 0.096359743 0.47242084 0.14551615 -0.5737531 -1.3282793     9
##  4:      PE 0.141271443 0.47242084 0.11331291 -0.4437498 -1.2356147    23
##  5:  HexCer 0.187134503 0.47242084 0.25296112  0.5692884  1.2148586     4
##  6:    PE O 0.188968335 0.47242084 0.09592068 -0.4417600 -1.1828169    18
##  7:      DG 0.301455301 0.64597565 0.07147863 -0.4426707 -1.1169071    13
##  8:      PI 0.348002684 0.65250503 0.20350896  0.2322835  0.9729923    17
##  9:      PC 0.452811245 0.75468541 0.05039643 -0.3647779 -1.0283733    25
## 10:      CL 0.539539540 0.79354553 0.04224682 -0.3473464 -0.9855149    27
## 11:     Cer 0.600877193 0.79354553 0.04148804 -0.4163695 -0.9126322     7
## 12:      PG 0.661272923 0.79354553 0.03630185 -0.3902271 -0.8856146     8
## 13:      FC 0.687739464 0.79354553 0.06103637  0.6666667  0.8888931     1
## 14:    PC O 0.899897855 0.94764398 0.01683805 -0.2733929 -0.7273005    17
## 15:      PS 0.947643979 0.94764398 0.01485926 -0.2528732 -0.6250262    12
##      leadingEdge
##           <list>
##  1: TG 53:1,....
##  2: CE 20:2,....
##  3: SM 41:2;....
##  4: PE 36:1,....
##  5: HexCer 4....
##  6: PE O-38:....
##  7: DG 34:1,....
##  8: PI 40:5,....
##  9: PC 38:4,....
## 10: CL 72:3,....
## 11: Cer 42:1....
## 12: PG 34:1,....
## 13:           FC
## 14: PC O-36:....
## 15: PS 36:1,....

2.10 ALL PunA

all_punA = function(cellLine){
  
  res_list <- lapply(fit_list, function(x) test_diff(x, 
                         paste0(cellLine,"_PunA2.5 - ",
                                cellLine,"_Control"),
                       alternative = "two.sided",
                       pval_adjust_method = "BH",
                       sort_by = NULL,
                       verbose = F))
  res_PunA1 <-  do.call(rbind,res_list)
  res_PunA1$adj_pval <- p.adjust(res_PunA1$pval, method = "fdr")
  
  res_PunA1 = res_PunA1 %>%
      as_tibble() %>% dplyr::rename("lipid" = "name", 
                             "adj.P.Val" = "adj_pval")%>% 
  rename_all(~paste0(.x,"_PunA2.5"))

  
  res_list <- lapply(fit_list, function(x) test_diff(x, 
                         paste0(cellLine,"_PunA5 - ",
                                cellLine,"_Control"),
                       alternative = "two.sided",
                       pval_adjust_method = "BH",
                       sort_by = NULL,
                       verbose = F))
  res_PunA2 <-  do.call(rbind,res_list)
  res_PunA2$adj_pval <- p.adjust(res_PunA2$pval, method = "fdr")
  
  res_PunA2 = res_PunA2 %>%
        as_tibble() %>% dplyr::rename("lipid" = "name", 
                               "adj.P.Val" = "adj_pval")%>% 
    rename_all(~paste0(.x,"_PunA5"))
  
   res_list <- lapply(fit_list, function(x) test_diff(x, 
                         paste0(cellLine,"_PunA10 - ",
                                cellLine,"_Control"),
                       alternative = "two.sided",
                       pval_adjust_method = "BH",
                       sort_by = NULL,
                       verbose = F))
  res_PunA3 <-  do.call(rbind,res_list)
  res_PunA3$adj_pval <- p.adjust(res_PunA3$pval, method = "fdr")
  
  res_PunA3 = res_PunA3 %>%
        as_tibble() %>% dplyr::rename("lipid" = "name", 
                               "adj.P.Val" = "adj_pval") %>% 
    rename_all(~paste0(.x,"_PunA10"))
  
  
  df <- res_PunA1 %>% 
    inner_join(res_PunA2, by = c("lipid_PunA2.5"="lipid_PunA5")) %>% 
    inner_join(res_PunA3, by = c("lipid_PunA2.5"="lipid_PunA10"))  %>% 
    dplyr::rename("lipid_name"=lipid_PunA2.5) %>% 
    left_join(rownames_to_column(as.data.frame(rd)), 
              by = c("lipid_name"="rowname")) %>% 
    select(c(lipid_name,Lipid_Class, contains("diff"), 
             contains("adj.P.Val")))
  
  colnames(df) = sub("diff_","logFC_",colnames(df))
  colnames(df) = sub("adj.P.Val_","adjpval_",colnames(df))
  
  df_long = df %>% 
    pivot_longer(cols = c(contains("logFC_"),
                          contains("adjpval_"))) %>% 
      mutate(test = sub("logFC_|adjpval_","",name),
             name = sub("_.*","",name))%>%  
      pivot_wider(names_from = name, values_from = value)
  df_long$test = factor(df_long$test, 
                        levels = c("PunA2.5","PunA5","PunA10"))
  df_long$signif = df_long$adjpval<0.05
  
  p = df_long %>% ggplot(aes(x = test, y = logFC,
                         group = lipid_name)) +
    geom_line(color="darkgray", alpha=0.7) + 
    facet_wrap(~ Lipid_Class, scales = "free", ncol=3) +
    geom_point(aes(color=signif), alpha=0.7) + 
    scale_color_manual(values = c("darkgray","red")) +
    ggtitle(cellLine)
  p
}
p = all_punA("X22RV1")
p

ggplotly(p)
p = all_punA("LNCaP")
p

ggplotly(p)
p = all_punA("PC3")
p

ggplotly(p)

3 sessionInfo

sessionInfo()
## R version 4.3.0 (2023-04-21)
## Platform: x86_64-apple-darwin20 (64-bit)
## Running under: macOS Ventura 13.6.1
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: Europe/Brussels
## tzcode source: internal
## 
## attached base packages:
##  [1] parallel  grid      stats4    stats     graphics  grDevices utils    
##  [8] datasets  methods   base     
## 
## other attached packages:
##  [1] fgsea_1.28.0                GGally_2.2.1               
##  [3] Vennerable_3.0              xtable_1.8-6               
##  [5] gtools_3.9.5                reshape_0.8.9              
##  [7] RColorBrewer_1.1-3          RBGL_1.78.0                
##  [9] graph_1.80.0                clusterProfiler_4.10.0     
## [11] doParallel_1.0.17           iterators_1.0.14           
## [13] foreach_1.5.2               missForest_1.5             
## [15] lipidr_2.16.0               patchwork_1.2.0            
## [17] limma_3.58.1                proDA_1.16.0               
## [19] UpSetR_1.4.0                knitr_1.45                 
## [21] glmnet_4.1-8                Matrix_1.6-5               
## [23] randomForest_4.7-1.1        caret_6.0-94               
## [25] lattice_0.22-5              xlsx_0.6.5                 
## [27] plotly_4.10.4               viridis_0.6.5              
## [29] viridisLite_0.4.2           ComplexHeatmap_2.18.0      
## [31] FactoMineR_2.10             factoextra_1.0.7           
## [33] readxl_1.4.3                gplots_3.1.3.1             
## [35] missMDA_1.19                QFeatures_1.12.0           
## [37] MultiAssayExperiment_1.28.0 pander_0.6.5               
## [39] ggrepel_0.9.5               lubridate_1.9.3            
## [41] forcats_1.0.0               stringr_1.5.1              
## [43] purrr_1.0.2                 readr_2.1.5                
## [45] tidyr_1.3.1                 tibble_3.2.1               
## [47] tidyverse_2.0.0             SummarizedExperiment_1.32.0
## [49] Biobase_2.62.0              GenomicRanges_1.54.1       
## [51] GenomeInfoDb_1.38.6         IRanges_2.36.0             
## [53] S4Vectors_0.40.2            BiocGenerics_0.48.1        
## [55] MatrixGenerics_1.14.0       matrixStats_1.2.0          
## [57] dplyr_1.1.4                 ggplot2_3.5.0              
## 
## loaded via a namespace (and not attached):
##   [1] nnet_7.3-19             DT_0.32                 Biostrings_2.70.2      
##   [4] TH.data_1.1-2           vctrs_0.6.5             digest_0.6.34          
##   [7] png_0.1-8               shape_1.4.6.1           parallelly_1.37.1      
##  [10] MASS_7.3-60.0.1         reshape2_1.4.4          qvalue_2.34.0          
##  [13] withr_3.0.0             MultiDataSet_1.30.0     ropls_1.34.0           
##  [16] xfun_0.42               ggfun_0.1.4             ellipsis_0.3.2         
##  [19] survival_3.5-8          doRNG_1.8.6             memoise_2.0.1          
##  [22] gmm_1.8                 emmeans_1.10.0          gson_0.1.0             
##  [25] calibrate_1.7.7         tidytree_0.4.6          zoo_1.8-12             
##  [28] GlobalOptions_0.1.2     KEGGREST_1.42.0         scatterplot3d_0.3-44   
##  [31] httr_1.4.7              globals_0.16.2          rstudioapi_0.15.0      
##  [34] pan_1.9                 generics_0.1.3          DOSE_3.28.2            
##  [37] curl_5.2.1              zlibbioc_1.48.0         ggraph_2.2.0           
##  [40] polyclip_1.10-6         GenomeInfoDbData_1.2.11 SparseArray_1.2.4      
##  [43] evaluate_0.23           S4Arrays_1.2.0          BiocFileCache_2.10.1   
##  [46] hms_1.1.3               colorspace_2.1-0        filelock_1.0.3         
##  [49] magrittr_2.0.3          ggtree_3.10.1           MsCoreUtils_1.14.1     
##  [52] future.apply_1.11.1     shadowtext_0.1.3        cowplot_1.1.3          
##  [55] class_7.3-22            pillar_1.9.0            nlme_3.1-164           
##  [58] caTools_1.18.2          compiler_4.3.0          stringi_1.8.3          
##  [61] gower_1.0.1             jomo_2.7-6              minqa_1.2.6            
##  [64] tmvtnorm_1.6            extraDistr_1.10.0       plyr_1.8.9             
##  [67] crayon_1.5.2            abind_1.4-5             gridGraphics_0.5-1     
##  [70] graphlayouts_1.1.0      bit_4.0.5               sandwich_3.1-0         
##  [73] pcaMethods_1.94.0       fastmatch_1.1-4         codetools_0.2-19       
##  [76] multcomp_1.4-25         recipes_1.0.10          crosstalk_1.2.1        
##  [79] bslib_0.6.1             GetoptLong_1.0.5        splines_4.3.0          
##  [82] circlize_0.4.16         Rcpp_1.0.12             dbplyr_2.4.0           
##  [85] HDO.db_0.99.1           cellranger_1.1.0        leaps_3.1              
##  [88] blob_1.2.4              utf8_1.2.4              clue_0.3-65            
##  [91] AnnotationFilter_1.26.0 lme4_1.1-35.1           itertools_0.1-3        
##  [94] fs_1.6.3                listenv_0.9.1           ggplotify_0.1.2        
##  [97] estimability_1.5        statmod_1.5.0           tzdb_0.4.0             
## [100] tweenr_2.0.3            pkgconfig_2.0.3         tools_4.3.0            
## [103] cachem_1.0.8            RSQLite_2.3.5           DBI_1.2.2              
## [106] impute_1.76.0           fastmap_1.1.1           rmarkdown_2.25         
## [109] scales_1.3.0            broom_1.0.5             sass_0.4.8             
## [112] coda_0.19-4.1           ggstats_0.5.1           rpart_4.1.23           
## [115] farver_2.1.1            tidygraph_1.3.1         scatterpie_0.2.1       
## [118] yaml_2.3.8              cli_3.6.2               lifecycle_1.0.4        
## [121] mvtnorm_1.2-4           lava_1.7.3              backports_1.4.1        
## [124] BiocParallel_1.36.0     timechange_0.3.0        gtable_0.3.4           
## [127] rjson_0.2.21            pROC_1.18.5             ape_5.7-1              
## [130] jsonlite_1.8.8          mitml_0.4-5             bitops_1.0-7           
## [133] multcompView_0.1-9      bit64_4.0.5             yulab.utils_0.1.4      
## [136] mice_3.16.0             highr_0.10              jquerylib_0.1.4        
## [139] GOSemSim_2.28.1         imputeLCMD_2.1          timeDate_4032.109      
## [142] lazyeval_0.2.2          htmltools_0.5.7         rJava_1.0-11           
## [145] enrichplot_1.22.0       GO.db_3.18.0            glue_1.7.0             
## [148] XVector_0.42.0          RCurl_1.98-1.14         treeio_1.26.0          
## [151] gridExtra_2.3           boot_1.3-30             flashClust_1.01-2      
## [154] igraph_2.0.2            R6_2.5.1                labeling_0.4.3         
## [157] xlsxjars_0.6.1          cluster_2.1.6           rngtools_1.5.2         
## [160] aplot_0.2.2             ipred_0.9-14            nloptr_2.0.3           
## [163] DelayedArray_0.28.0     tidyselect_1.2.0        ProtGenerics_1.34.0    
## [166] ggforce_0.4.2           qqman_0.1.9             AnnotationDbi_1.64.1   
## [169] future_1.33.1           ModelMetrics_1.2.2.2    munsell_0.5.0          
## [172] KernSmooth_2.23-22      data.table_1.15.2       htmlwidgets_1.6.4      
## [175] rlang_1.1.3             Cairo_1.6-2             norm_1.0-11.1          
## [178] fansi_1.0.6             hardhat_1.3.1           prodlim_2023.08.28